<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover"><title>Oracle基本语法 | XuanCode</title><meta name="author" content="xuanskeys"><meta name="copyright" content="xuanskeys"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="前言： 1.使用的数据库不同，所使用的语法也略有不同 2.SQL对大小写不敏感 3.Oracle中对引号里面的内容大小写敏感 3.表空间名、文件路径……等需要用单引号将其包含 4.一般引号里面的内容需要大写   准备工作：安装tips：PLSQL、Oracle以及客户端远程连接服务器笔记（仅供参考）-CSDN博客  （1）.Win+R打开services.msc     （2）启动一些服务： （q">
<meta property="og:type" content="article">
<meta property="og:title" content="Oracle基本语法">
<meta property="og:url" content="http://xuanskeys.github.io/2025/04/20/Oracle/index.html">
<meta property="og:site_name" content="XuanCode">
<meta property="og:description" content="前言： 1.使用的数据库不同，所使用的语法也略有不同 2.SQL对大小写不敏感 3.Oracle中对引号里面的内容大小写敏感 3.表空间名、文件路径……等需要用单引号将其包含 4.一般引号里面的内容需要大写   准备工作：安装tips：PLSQL、Oracle以及客户端远程连接服务器笔记（仅供参考）-CSDN博客  （1）.Win+R打开services.msc     （2）启动一些服务： （q">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="http://xuanskeys.github.io/image/person.jpg">
<meta property="article:published_time" content="2025-04-20T01:52:13.000Z">
<meta property="article:modified_time" content="2025-04-20T01:54:15.271Z">
<meta property="article:author" content="xuanskeys">
<meta property="article:tag" content="1">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="http://xuanskeys.github.io/image/person.jpg"><script type="application/ld+json">{
  "@context": "https://schema.org",
  "@type": "BlogPosting",
  "headline": "Oracle基本语法",
  "url": "http://xuanskeys.github.io/2025/04/20/Oracle/",
  "image": "http://xuanskeys.github.io/image/person.jpg",
  "datePublished": "2025-04-20T01:52:13.000Z",
  "dateModified": "2025-04-20T01:54:15.271Z",
  "author": [
    {
      "@type": "Person",
      "name": "xuanskeys",
      "url": "http://xuanskeys.github.io/"
    }
  ]
}</script><link rel="shortcut icon" href="/image/%E5%AF%BF%E5%8F%B8.png"><link rel="canonical" href="http://xuanskeys.github.io/2025/04/20/Oracle/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css"><script>
    (() => {
      
    const saveToLocal = {
      set: (key, value, ttl) => {
        if (!ttl) return
        const expiry = Date.now() + ttl * 86400000
        localStorage.setItem(key, JSON.stringify({ value, expiry }))
      },
      get: key => {
        const itemStr = localStorage.getItem(key)
        if (!itemStr) return undefined
        const { value, expiry } = JSON.parse(itemStr)
        if (Date.now() > expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return value
      }
    }

    window.btf = {
      saveToLocal,
      getScript: (url, attr = {}) => new Promise((resolve, reject) => {
        const script = document.createElement('script')
        script.src = url
        script.async = true
        Object.entries(attr).forEach(([key, val]) => script.setAttribute(key, val))
        script.onload = script.onreadystatechange = () => {
          if (!script.readyState || /loaded|complete/.test(script.readyState)) resolve()
        }
        script.onerror = reject
        document.head.appendChild(script)
      }),
      getCSS: (url, id) => new Promise((resolve, reject) => {
        const link = document.createElement('link')
        link.rel = 'stylesheet'
        link.href = url
        if (id) link.id = id
        link.onload = link.onreadystatechange = () => {
          if (!link.readyState || /loaded|complete/.test(link.readyState)) resolve()
        }
        link.onerror = reject
        document.head.appendChild(link)
      }),
      addGlobalFn: (key, fn, name = false, parent = window) => {
        if (!false && key.startsWith('pjax')) return
        const globalFn = parent.globalFn || {}
        globalFn[key] = globalFn[key] || {}
        globalFn[key][name || Object.keys(globalFn[key]).length] = fn
        parent.globalFn = globalFn
      }
    }
  
      
      const activateDarkMode = () => {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      const activateLightMode = () => {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }

      btf.activateDarkMode = activateDarkMode
      btf.activateLightMode = activateLightMode

      const theme = saveToLocal.get('theme')
    
          theme === 'dark' ? activateDarkMode() : theme === 'light' ? activateLightMode() : null
        
      
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        document.documentElement.classList.toggle('hide-aside', asideStatus === 'hide')
      }
    
      
    const detectApple = () => {
      if (/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)) {
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
  
    })()
  </script><script>const GLOBAL_CONFIG = {
  root: '/',
  algolia: undefined,
  localSearch: {"path":"/search.xml","preload":false,"top_n_per_article":1,"unescape":false,"languages":{"hits_empty":"未找到符合您查询的内容：${query}","hits_stats":"共找到 ${hits} 篇文章"}},
  translate: undefined,
  highlight: {"plugin":"highlight.js","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false,"highlightFullpage":false,"highlightMacStyle":false},
  copy: {
    success: '复制成功',
    error: '复制失败',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  dateSuffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'null',
  Snackbar: undefined,
  infinitegrid: {
    js: 'https://cdn.jsdelivr.net/npm/@egjs/infinitegrid/dist/infinitegrid.min.js',
    buttonText: '加载更多'
  },
  isPhotoFigcaption: false,
  islazyloadPlugin: false,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: false,
  },
  autoDarkmode: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'Oracle基本语法',
  isHighlightShrink: false,
  isToc: true,
  pageType: 'post'
}</script><link rel="stylesheet" href="/styles/main.css"><script src="/styles/fish.js"></script><script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script><meta name="generator" content="Hexo 7.3.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><script>(()=>{
  const $loadingBox = document.getElementById('loading-box')
  const $body = document.body
  const preloader = {
    endLoading: () => {
      $body.style.overflow = ''
      $loadingBox.classList.add('loaded')
    },
    initLoading: () => {
      $body.style.overflow = 'hidden'
      $loadingBox.classList.remove('loaded')
    }
  }

  preloader.initLoading()
  window.addEventListener('load', preloader.endLoading)

  if (false) {
    btf.addGlobalFn('pjaxSend', preloader.initLoading, 'preloader_init')
    btf.addGlobalFn('pjaxComplete', preloader.endLoading, 'preloader_end')
  }
})()</script><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img text-center"><img src="/image/person.jpg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data text-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">10</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">1</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">5</div></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><span class="site-page group"><i class="fa-fw fa fa-heartbeat"></i><span> 清单</span><i class="fas fa-chevron-down"></i></span><ul class="menus_item_child"><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/Gallery/"><i class="fa-fw fas fa-images"></i><span> 照片</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li></ul></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url(/image/background.jpg);"><nav id="nav"><span id="blog-info"><a class="nav-site-title" href="/"><span class="site-name">XuanCode</span></a><a class="nav-page-title" href="/"><span class="site-name">Oracle基本语法</span></a></span><div id="menus"><div id="search-button"><span class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></span></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 时间轴</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></div><div class="menus_item"><span class="site-page group"><i class="fa-fw fa fa-heartbeat"></i><span> 清单</span><i class="fas fa-chevron-down"></i></span><ul class="menus_item_child"><li><a class="site-page child" href="/music/"><i class="fa-fw fas fa-music"></i><span> 音乐</span></a></li><li><a class="site-page child" href="/Gallery/"><i class="fa-fw fas fa-images"></i><span> 照片</span></a></li><li><a class="site-page child" href="/movies/"><i class="fa-fw fas fa-video"></i><span> 电影</span></a></li></ul></div></div><div id="toggle-menu"><span class="site-page"><i class="fas fa-bars fa-fw"></i></span></div></div></nav><div id="post-info"><h1 class="post-title">Oracle基本语法</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2025-04-20T01:52:13.000Z" title="发表于 2025-04-20 09:52:13">2025-04-20</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2025-04-20T01:54:15.271Z" title="更新于 2025-04-20 09:54:15">2025-04-20</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E6%95%B0%E6%8D%AE%E5%BA%93/">数据库</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title=""><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">浏览量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="container post-content" id="article-container"><h1><span id="前言">前言：</span></h1><blockquote>
<p>1.使用的数据库不同，所使用的语法也略有不同</p>
<p>2.SQL对大小写不敏感</p>
<p>3.Oracle中对引号里面的内容大小写敏感</p>
<p>3.表空间名、文件路径……等需要用单引号将其包含</p>
<p>4.一般引号里面的内容需要大写</p>
</blockquote>
<hr>
<h1><span id="准备工作">准备工作：</span></h1><p><strong>安装tips：</strong><a target="_blank" rel="noopener" href="https://blog.csdn.net/m0_73569492/article/details/139752761?spm=1001.2014.3001.5501">PLSQL、Oracle以及客户端远程连接服务器笔记（仅供参考）-CSDN博客</a></p>
<blockquote>
<p>（1）.Win+R打开services.msc</p>
<p> <img src="/./../images/66f21500c6889f5bcedc4d9d35afd3f2.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<p> （2）启动一些服务：</p>
<p>（qwq我不知道哪些有用，哪些没用，所以我都把打开了，不知道有没有负面影响，大家参考一下别的博客吧）</p>
<p><img src="/./../images/14d9eb7b4c10dd713aed7092ce49302b.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
</blockquote>
<hr>
<h1><span id="登录">登录：</span></h1><h2><span id="1打开sql-plus命令行工具">1.打开SQL Plus命令行工具</span></h2><h3><span id="第一种方式">第一种方式：</span></h3><p><img src="/./../images/d22f6a21e6fe7c298f14cc4c9ac5e7ca.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<h3><span id="第二种方式">第二种方式：</span></h3><blockquote>
<p>（1）win+R 打开cmd</p>
<p><img src="/./../images/1ed922a4a00b95425d8d0efd76d3311f.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<p>（2）输入sqlplus</p>
<p><img src="/./../images/ebc2811f72afc289d8f1dea3bce83143.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
</blockquote>
<h2><span id="2以不同用户登录">2.以不同用户登录</span></h2><blockquote>
<p><strong>注意：</strong></p>
<p>1.使用用户口令这种形式登录的时候，是不显示密码的，口令输入的时候是不显示的，直接输就好</p>
<p>2.若是想以显示密码的形式输入，直接在用户名那一块输入：用户名&#x2F;密码</p>
<p>3.超级管理员（sys）输入时需要注意指定 as sysdba</p>
</blockquote>
<h4><span id="system普通管理员">SYSTEM（普通管理员）：</span></h4><p><img src="/./../images/150ff3d4c0894edfa6605790d3110aad.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<h4><span id="sys超级管理员">SYS(超级管理员)：</span></h4><blockquote>
<h5><span id="不显示密码方式">不显示密码方式：</span></h5><p>用户名：SYS</p>
<p>密码：sys密码 as sysdba</p>
<p><img src="/./../images/3abea06f433979383dd0d214cbbca90a.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<h5><span id="显示密码方式">显示密码方式：</span></h5><p>用户名：sys&#x2F;sys密码 as sysdba</p>
<p><img src="/./../images/904f8705b5d5e728bb206d3fa3cab571.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
</blockquote>
<h4><span id="scott普通用户"><strong>SCOTT（普通用户）：</strong></span></h4><h5><span id="若是出现被锁住的情况">若是出现被锁住的情况：<img src="/./../images/f5e98d05ffb12c89c35ebf8471e9a104.png" alt="img"><img src="" alt="点击并拖拽以移动"></span></h5><h5><span id="解决方法">解决方法：</span></h5><blockquote>
<p>（1）登录超级管理员账户，</p>
<p><img src="/./../images/5ec0cf3f2f86a2dd7d0988837066cd5b.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<p>（2）输入alter user 用户名 account unlock; </p>
<p> <img src="/./../images/906ad87ef7add1c30ffe69c40a50be01.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<p>（3）重新登录即可：</p>
<p><img src="/./../images/c28535fe5646d39e25bbc211a65828a1.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
</blockquote>
<hr>
<h1><span id="sql基本命令">SQL基本命令</span></h1><p><img src="/./../images/98658ad698cd7b5a48f441016869fa34.jpeg" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<hr>
<h1><span id="1数据定义语言ddl">1.数据定义语言（DDL）</span></h1><h2><span id="数据库操作">数据库操作</span></h2><h3><span id="查询所有用户">查询所有用户：</span></h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> <span class="keyword">distinct</span>(OWNER) <span class="keyword">from</span> all_tables;</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<h3><span id="查看当前用户">查看当前用户：</span></h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">show</span> <span class="keyword">user</span>;</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<p><img src="/./../images/b9f03916007d4bd174be2ed464017538.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<h3><span id="创建表空间">创建表空间：</span></h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">create</span> tablespace 表空间名 datafile <span class="string">&#x27;存储路径\***.dbf&#x27;</span> size 空间大小;</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<p><img src="/./../images/24aef2d0cb1fe0191097b17fd1294117.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<h3><span id="创建用户并指定其表空间">创建用户并指定其表空间：</span></h3><p>（指定表空间需要先创建表空间，如果不指定表空间，就会按照默认空间存储）</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">create</span> <span class="keyword">user</span> 用户名 identified <span class="keyword">by</span> 密码 <span class="keyword">default</span> tablespace 表空间;</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<p><img src="/./../images/924f0a327e10c2568c15518c3a86c42e.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<h3><span id="给用户授予dba的权限超级管理员">给用户授予dba的权限（超级管理员）：</span></h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">grant</span> dba <span class="keyword">to</span> 用户;</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<h3><span id><img src="/./../images/bc0384bd54b4e601d5559602c6c8631e.png" alt="img"><img src="" alt="点击并拖拽以移动"></span></h3><h3><span id="删除表空间">删除表空间：</span></h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">drop</span> tablespace 表空间名 including contents <span class="keyword">and</span> datafiles;</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<p><img src="/./../images/8d1b79d04f89ecd80ae390f568854c2d.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<h3><span id="删除用户超级管理员">删除用户（超级管理员）：</span></h3><blockquote>
<p>（1）查看用户是否有活跃对话</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> sid <span class="keyword">as</span> session_id, serial# <span class="keyword">from</span> v$session <span class="keyword">where</span> username<span class="operator">=</span><span class="string">&#x27;用户名&#x27;</span>;</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<p><img src="/./../images/9af806c2c99cf6062fdc7571e420de59.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<p>（2）如果查询结果显示有活动的会话，结束这些会话</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">kill session <span class="string">&#x27;session_id, serial#&#x27;</span> immediate;</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<p> (3）删除用户</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">drop</span> <span class="keyword">user</span> 用户名 cascade;</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<p><img src="/./../images/63dd338382437ad93ce4b38f2929268e.png" alt="img"><img src="" alt="点击并拖拽以移动">  </p>
</blockquote>
<h3><span id="切换用户登录">切换用户登录：</span></h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">conn 用户名<span class="operator">/</span>密码</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<p><img src="/./../images/a292d3f38a92840137bbb4247c9b7687.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<h2><span id="表操作">表操作</span></h2><h3><span id="查询">查询：</span></h3><h4><span id="查询某个用户下所有表名"><strong>查询某个用户下所有表名：</strong></span></h4><p>（用户名注意大写）</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> table_name <span class="keyword">from</span> dba_tables <span class="keyword">where</span> owner <span class="operator">=</span> <span class="string">&#x27;用户名&#x27;</span>;</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<p><img src="/./../images/be6ce051047552442d03be89b4e2274b.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<h4><span id="查询某个用户下表个数">查询某个用户下表个数：</span></h4><p>（用户名注意大写）</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> <span class="built_in">count</span>(<span class="operator">*</span>) <span class="keyword">from</span> all_tables <span class="keyword">where</span> OWNER <span class="operator">=</span> <span class="string">&#x27;用户名&#x27;</span>;</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<p><img src="/./../images/367f672553435c3ac232705527ed7f41.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<h4><span id="查询某个用户的表结构">查询某个用户的表结构：</span></h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">desc</span> 用户名.表名;</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<p><img src="/./../images/171a028451208aa6929f37c7671424f3.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<h4><span id="查询指定表的建表语句">查询指定表的建表语句：</span></h4><p>（表名、用户名注意大写）</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> dbms_metadata.get_ddl(<span class="string">&#x27;TABLE&#x27;</span>, <span class="string">&#x27;表名&#x27;</span>,<span class="string">&#x27;用户名&#x27;</span>) <span class="keyword">from</span> dual;</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<p><img src="/./../images/8ad81ae56c0961d80e7a51125ad81097.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<h3><span id="创建">创建：</span></h3><h4><span id="数据类型">数据类型：</span></h4><p><img src="/./../images/a47b10c00ca70607ce74f5815b32a3c0.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<h4><span id="创建表空间">创建表空间：</span></h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">create</span> tablespace 表空间名 datafile <span class="string">&#x27;文件路径\文件名.dbf&#x27;</span> size 表空间大小;</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<h5><span id><img src="/./../images/d31d2556cebf7fadca29ee70400fcf45.png" alt="img"><img src="" alt="点击并拖拽以移动"></span></h5><p> <img src="/./../images/c88dc810ae93a774b0880d84bc972c83.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<h4><span id="创建表">创建表：</span></h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">#创建表</span><br><span class="line"><span class="keyword">create table</span> 表名(</span><br><span class="line"></span><br><span class="line">        字段<span class="number">1</span> 字段<span class="number">1</span>类型,</span><br><span class="line"></span><br><span class="line">        字段<span class="number">2</span> 字段<span class="number">2</span>类型,</span><br><span class="line"></span><br><span class="line">        字段<span class="number">3</span> 字段<span class="number">3</span>类型,</span><br><span class="line"></span><br><span class="line">        .......</span><br><span class="line"></span><br><span class="line">        字段n 字段n类型</span><br><span class="line"></span><br><span class="line">) ;       </span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<p><img src="/./../images/70a79f2192ebf673580f916ed795af6f.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<h4><span id="给表添加注释">给表添加注释：</span></h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">comment <span class="keyword">on</span> <span class="keyword">table</span> 表名 <span class="keyword">is</span> <span class="string">&#x27;注释&#x27;</span>;</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<p> <img src="/./../images/97a48f36749ac3b74a04af96d6ad44dd.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<h4><span id="给字段添加注释">给字段添加注释：</span></h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">comment <span class="keyword">on</span> <span class="keyword">column</span> 表名.字段名 <span class="keyword">is</span> <span class="string">&#x27;注释&#x27;</span>;</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<p><img src="/./../images/991d95413bf6e1e11abd85f4486120c1.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<h4><span id="表备份">表备份：</span></h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">create table</span> 用户名.备份表名 <span class="keyword">as</span> <span class="keyword">select</span> <span class="operator">*</span> <span class="keyword">from</span> 用户名.需要备份的表名;</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<p><img src="/./../images/fc79e9c62d2d7dd97d2d76a759d2419b.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<p> <img src="/./../images/878fa76ee8e2b04a3a1b01f815d2713d.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<p><img src="/./../images/31ea1e34d5ad34cd6c52fb315e950768.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<h4><span id="给表添加一列">给表添加一列：</span></h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">alter table</span> 表名 <span class="keyword">add</span> (字段名 字段类型 约束条件);</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<p><img src="/./../images/893c185ac9697fe5de01fec32bea7f7d.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<h3><span id="修改">修改：</span></h3><h4><span id="重命名表">重命名表：</span></h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">alter table</span> 用户名.旧表名 rename <span class="keyword">to</span> 新表名;</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<p><img src="/./../images/02bb529b23d639e86c703f3fa368bea3.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<h4><span id="添加字段">添加字段：</span></h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">alter table</span> 用户名.表名 <span class="keyword">add</span> 新字段名 新字段类型 <span class="keyword">default</span> <span class="string">&#x27;默认值&#x27;</span>;</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<p><img src="/./../images/1ba09a5aa85313b72caaa0d11ffb5cc6.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<h4><span id="修改字段名">修改字段名：</span></h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">alter table</span> 用户名.表名 rename <span class="keyword">column</span> 旧字段名 <span class="keyword">to</span> 新字段名;</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<p><img src="/./../images/6162c20c11fddf5d7b05fe031f4a6775.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<h4><span id="修改数据类型">修改数据类型：</span></h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">alter table</span> T1.emp1 modify temp <span class="type">varchar</span>(<span class="number">30</span>);</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<p><img src="/./../images/cd672986b9de36355caf918cbf7d0fb6.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<h3><span id="删除">删除：</span></h3><h4><span id="删除表字段">删除表字段：</span></h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">alter table</span> 用户名.表名 <span class="keyword">drop</span> <span class="keyword">column</span> 字段名;</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<p><img src="/./../images/9252aab3e184421c2f4b4fdf356d69df.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<h4><span id="删除表">删除表：</span></h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">drop</span> <span class="keyword">table</span> 表名;</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<p><img src="/./../images/2adba3f4a8316d7a8e910eb3b71e5e33.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<h4><span id="删除表空间">删除表空间：</span></h4><blockquote>
<p>（1）查看是否有其它用户在使用该表空间：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> <span class="operator">*</span> <span class="keyword">from</span> dba_users <span class="keyword">where</span> default_tablespace<span class="operator">=</span><span class="string">&#x27;表空间名&#x27;</span>;</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<p><img src="/./../images/c62561547930d3006de3a9de405c050b.png" alt="img"><img src="" alt="点击并拖拽以移动"> （2）若有，则删除这些用户或者将这些用户迁移到别的表空间</p>
<p>（3）删除表空间</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">drop</span> tablespace 表空间名 including contents <span class="keyword">and</span> datafiles;</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<p><img src="/./../images/68a0992605cde01197c229e6a0d14b78.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<p><img src="/./../images/a5d08f83c758e1703f5485adb6b222a1.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
</blockquote>
<h4><span id="删除指定表并重新创建该表">删除指定表并重新创建该表：</span></h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">truncate</span> <span class="keyword">table</span> 表名;</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<p><img src="/./../images/0d70f6f41a838eb41e51f763fd174cc7.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<hr>
<h1><span id="2数据操作语言dml">2.数据操作语言（DML）</span></h1><h2><span id="添加数据insert">添加数据（insert）</span></h2><blockquote>
<p>注意：</p>
<p>1.插入数据注意顺序</p>
<p>2.插入的数据大小要合法</p>
</blockquote>
<h3><span id="给指定字段添加数据">给指定字段添加数据：</span></h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">insert into</span> 表名 (字段<span class="number">1</span>，字段<span class="number">2.</span>.....) <span class="keyword">values</span>(值<span class="number">1</span>， 值<span class="number">2.</span>.....);</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<p><img src="/./../images/2a3256069ff327c8945b6f69822356b7.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<h3><span id="给表中批量添加数据">给表中批量添加数据：</span></h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">insert</span> <span class="keyword">all</span> <span class="keyword">into</span> 用户名.表名(字段<span class="number">1</span>，字段<span class="number">2</span>，字段<span class="number">3.</span>.....) <span class="keyword">values</span>(值<span class="number">1</span>，值<span class="number">2</span>，值<span class="number">3.</span>......)</span><br><span class="line">           <span class="keyword">into</span> 用户名.表名(字段<span class="number">1</span>，字段<span class="number">2</span>，字段<span class="number">3.</span>.....) <span class="keyword">values</span>(值<span class="number">1</span>，值<span class="number">2</span>，值<span class="number">3.</span>......)</span><br><span class="line"><span class="keyword">select</span> <span class="operator">*</span> <span class="keyword">from</span> dual;</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<p><img src="/./../images/61865314512c23512107c56044ae0c24.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<h2><span id="修改数据update">修改数据（update）</span></h2><h3><span id="修改数据">修改数据：</span></h3><p> 注意：如果没有条件，则会修改整张表</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">update</span> 表名 <span class="keyword">set</span> 字段<span class="number">1</span><span class="operator">=</span>值<span class="number">1</span>，字段<span class="number">2</span><span class="operator">=</span>值<span class="number">2.</span>.....[<span class="keyword">where</span> 条件];</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<p><img src="/./../images/448d63d4009d26e3c68c01e68cab276e.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<h2><span id="删除数据delete">删除数据（delete）</span></h2><h3><span id="删除数据">删除数据：</span></h3><p>注意：如果没有条件，则会删除整张表</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">delete</span> <span class="keyword">from</span> 表名;</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<h2><span id><img src="/./../images/a5bd875aa6273652f31415e3072e95cd.png" alt="img"><img src="" alt="点击并拖拽以移动"></span></h2><hr>
<h1><span id="3数据查询语言dql">3.数据查询语言（DQL）</span></h1><h2><span id="编写顺序">编写顺序：</span></h2><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> [<span class="keyword">distinct</span><span class="operator">|</span><span class="keyword">all</span>] 字段列表</span><br><span class="line"></span><br><span class="line"><span class="keyword">from</span> 表名</span><br><span class="line"></span><br><span class="line"><span class="keyword">where</span> 查询条件</span><br><span class="line"></span><br><span class="line"><span class="keyword">group</span> <span class="keyword">by</span> 分组字段列表</span><br><span class="line"></span><br><span class="line"><span class="keyword">having</span> 分组后条件列表</span><br><span class="line"></span><br><span class="line"><span class="keyword">order</span> <span class="keyword">by</span> 排序字段列表:<span class="keyword">asc</span>或者<span class="keyword">desc</span></span><br><span class="line">;</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<p><strong>作示范的表结构：</strong></p>
<p><img src="/./../images/84ea121a93f55bd7ce1e91018f26ff6b.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<p>表名：T_STUDENT</p>
<p><img src="/./../images/267618462c80e1e2dc172b7893a712d3.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<h2><span id="执行顺序">执行顺序：</span></h2><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">from</span> 表名 : 从哪张表查询</span><br><span class="line"></span><br><span class="line"><span class="keyword">where</span> 条件 ：查询条件</span><br><span class="line"></span><br><span class="line"><span class="keyword">group</span> <span class="keyword">by</span> 分组条件 ：分组</span><br><span class="line"></span><br><span class="line"><span class="keyword">having</span> 分组后查询条件 ：分组后查询条件</span><br><span class="line"></span><br><span class="line"><span class="keyword">select</span> 字段列表 ：选择字段</span><br><span class="line"></span><br><span class="line"><span class="keyword">order</span> <span class="keyword">by</span> 排序方式 ：对查询结果进行排序</span><br><span class="line">;</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<h2><span id="基本查询">基本查询</span></h2><h3><span id="查询多个字段">查询多个字段：</span></h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> 字段<span class="number">1</span>，字段<span class="number">2</span>，字段<span class="number">3.</span>..<span class="keyword">from</span> 表名;</span><br><span class="line"> </span><br><span class="line"><span class="keyword">select</span> <span class="operator">*</span> <span class="keyword">from</span> 表名;</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<h3><span id="设置别名">设置别名：</span></h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> 字段<span class="number">1</span>[<span class="keyword">as</span> 别名<span class="number">1</span>]，字段<span class="number">2</span> [<span class="keyword">as</span> 别名<span class="number">2</span>]......<span class="keyword">from</span> 表名;</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<p><img src="/./../images/517a020e1d96342be7c4ebc307573c1c.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<h3><span id="去除重复记录">去除重复记录：</span></h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> <span class="keyword">distinct</span> 字段列表 <span class="keyword">from</span> 表名;</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<h2><span id="条件查询">条件查询</span></h2><h3><span id="语法">语法：</span></h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> 字段列表 <span class="keyword">from</span> 表名 <span class="keyword">where</span> 条件列表;</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<h3><span id><img src="/./../images/1f49d960e33577adfcdf7eeb3dd409fb.png" alt="img"><img src="" alt="点击并拖拽以移动"></span></h3><h3><span id="条件">条件：</span></h3><table>
<thead>
<tr>
<th>比较运算符</th>
<th>功能</th>
</tr>
</thead>
<tbody><tr>
<td><strong>&gt;</strong></td>
<td></td>
</tr>
<tr>
<td><strong>&gt;&#x3D;</strong></td>
<td></td>
</tr>
<tr>
<td><strong>&lt;</strong></td>
<td></td>
</tr>
<tr>
<td><strong>&lt;&#x3D;</strong></td>
<td></td>
</tr>
<tr>
<td><strong>&#x3D;</strong></td>
<td></td>
</tr>
<tr>
<td><strong>&lt;&gt; 或 !&#x3D;</strong></td>
<td><strong>不等于</strong></td>
</tr>
<tr>
<td><strong>between…and…</strong></td>
<td><strong>在某个范围之内</strong></td>
</tr>
<tr>
<td><strong>in(…)</strong></td>
<td><strong>在in之后的括号中，多选一</strong></td>
</tr>
<tr>
<td><strong>like 占位符</strong></td>
<td><strong>模糊匹配（_匹配单个字符，%匹配任意个字符）</strong></td>
</tr>
<tr>
<td><strong>is null</strong></td>
<td></td>
</tr>
<tr>
<td><strong>and 或 &amp;&amp;</strong></td>
<td><strong>并且</strong></td>
</tr>
<tr>
<td><strong>or 或 ||</strong></td>
<td><strong>或</strong></td>
</tr>
<tr>
<td><strong>not 或 !</strong></td>
<td><strong>非</strong></td>
</tr>
</tbody></table>
<h2><span id="聚合函数">聚合函数</span></h2><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> 聚合函数(字段列表) <span class="keyword">from</span> 表名;</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<p><img src="/./../images/3ace072af958dfe6d3bde283221dd218.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<p><strong>注意：</strong></p>
<blockquote>
<p>​    对一列进行计算 所有null值不参与聚合函数的计算</p>
</blockquote>
<table>
<thead>
<tr>
<th>函数</th>
<th>功能</th>
</tr>
</thead>
<tbody><tr>
<td><strong>count</strong></td>
<td><strong>统计数量</strong></td>
</tr>
<tr>
<td><strong>max</strong></td>
<td><strong>最大值</strong></td>
</tr>
<tr>
<td><strong>min</strong></td>
<td><strong>最小值</strong></td>
</tr>
<tr>
<td><strong>avg</strong></td>
<td><strong>平均值</strong></td>
</tr>
<tr>
<td><strong>sum</strong></td>
<td><strong>求和</strong></td>
</tr>
</tbody></table>
<h2><span id="分组查询">分组查询</span></h2><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> 字段列表 <span class="keyword">from</span> 表名 [<span class="keyword">where</span> 条件] <span class="keyword">group</span> <span class="keyword">by</span> 分组字段名 [<span class="keyword">having</span> 分组后过滤条件];</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<table>
<thead>
<tr>
<th><strong>where</strong></th>
<th><code>**分组之前执行,不满足where条件的不参与分组,where不能对聚合函数进行判断**</code></th>
</tr>
</thead>
<tbody><tr>
<td><strong>having</strong></td>
<td><code>**分组之后对结果进行过滤,having可以对聚合函数进行判断**</code></td>
</tr>
</tbody></table>
<p><strong>eg:</strong></p>
<p><img src="/./../images/78d82815420085ae4f6ffc9443e03a69.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<h2><span id="排序查询">排序查询</span></h2><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> 字段列表 <span class="keyword">from</span> 表名 <span class="keyword">order</span> <span class="keyword">by</span> 字段<span class="number">1</span> 排序方式<span class="number">1</span>, 字段<span class="number">2</span> 排序方式<span class="number">2</span>;</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<table>
<thead>
<tr>
<th><strong>asc</strong></th>
<th><strong>升序（默认）</strong></th>
</tr>
</thead>
<tbody><tr>
<td><strong>desc</strong></td>
<td><strong>降序</strong></td>
</tr>
</tbody></table>
<p><img src="/./../images/e0e447c4e53eb881a3d2ca119f8c122e.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<h2><span id="分页查询">分页查询</span></h2><p>（oracle查询没有limit关键字，引入rownum进行分页查询）</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> <span class="operator">*</span> <span class="keyword">from</span></span><br><span class="line">(</span><br><span class="line">    <span class="keyword">select</span> rownum rn, t.<span class="operator">*</span> <span class="keyword">from</span></span><br><span class="line">    (<span class="keyword">select</span> 字段 <span class="keyword">from</span> t_student) t <span class="keyword">where</span> rownum <span class="operator">&lt;=</span> 终止行</span><br><span class="line">)</span><br><span class="line"> <span class="keyword">where</span> rn <span class="operator">&gt;=</span> 起始行;</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<p><img src="/./../images/340d704c3e8871247b5079b97015783a.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<hr>
<h1><span id="4数据控制语言dcl">4.数据控制语言（DCL）</span></h1><h2><span id="管理用户">管理用户</span></h2><h3><span id="查看当前用户">查看当前用户：</span></h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">show</span> <span class="keyword">user</span>;</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<p>切换用户：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">connect</span> 用户名<span class="operator">/</span>密码;</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<p><img src="/./../images/7d8df788d4b7667511eb525c30c9fb50.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<blockquote>
<p><strong>注意连接到数据库超级管理员的时候：</strong></p>
<p>可能会出现以下错误：</p>
<p><img src="/./../images/a8bad2101b308c24cfc3cf82c5f2ec9f.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<p>解决方法：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">connect</span> sys<span class="operator">/</span>密码 <span class="keyword">as</span> sysdba</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<p> <img src="/./../images/297797dfaa5c031c14e9365107675c8f.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
</blockquote>
<h2><span id="权限控制">权限控制</span></h2><h3><span id="查询用户权限">查询用户权限：</span></h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> <span class="operator">*</span> <span class="keyword">from</span> dba_sys_privs <span class="keyword">where</span> grantee<span class="operator">=</span><span class="string">&#x27;用户名&#x27;</span>;</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<h3><span id="授予权限">授予权限：</span></h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">grant</span> 权限 <span class="keyword">to</span> 用户;</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<table>
<thead>
<tr>
<th>权限</th>
<th>说明</th>
</tr>
</thead>
<tbody><tr>
<td>create session</td>
<td>登录权限</td>
</tr>
<tr>
<td>create table</td>
<td>创建表的权限</td>
</tr>
<tr>
<td>drop any table</td>
<td>删除任意表</td>
</tr>
<tr>
<td>insert any table</td>
<td>向任意表中插入行</td>
</tr>
<tr>
<td>update any table</td>
<td>修改任意表中行的权限</td>
</tr>
<tr>
<td>select on 表名</td>
<td>查看指定表的权限</td>
</tr>
</tbody></table>
<p> eg：</p>
<p><img src="/./../images/e344ac75542629b9995d51ba8338f84e.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<h3><span id="回收权限">回收权限：</span></h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">--回收用户权限</span></span><br><span class="line"><span class="keyword">revoke</span> 权限 <span class="keyword">from</span> 用户;</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">revoke</span> <span class="keyword">select</span> <span class="keyword">on</span> 用户<span class="number">2.</span>表<span class="number">2</span> <span class="keyword">from</span> 用户<span class="number">1</span>; #回收用户<span class="number">1</span>查看表<span class="number">2</span>的权限</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<p><img src="/./../images/ab244ed7fd0b1f6c9a79630b31c6dd7b.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<hr>
<h1><span id="函数">函数</span></h1><h2><span id="使用">使用</span></h2><blockquote>
<p>一般形式：</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> 函数 <span class="keyword">from</span> 表名 <span class="keyword">where</span> 条件;</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<p>如果只是想看函数的返回结果可以使用以下形式:</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> 函数 <span class="keyword">from</span> sys.dual;</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
</blockquote>
<h2><span id="sysdual">sys.dual</span></h2><blockquote>
<p>dual是一个虚拟表，用来构成select的语法规则，oracle保证dual里面永远只有一条记录</p>
</blockquote>
<h2><span id="字符串函数">字符串函数</span></h2><p>eg:</p>
<p> <img src="/./../images/fbd7bde2422e621029ccc8f9bf8fc83e.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<p><img src="/./../images/aff1fc564b0dbf782e06085d37208f48.png" alt="img"><img src="" alt="点击并拖拽以移动"> <img src="/./../images/6d53f8c375e4951c76cf448f727c3baa.png" alt="img"><img src="" alt="点击并拖拽以移动">  </p>
<h2><span id="数值函数">数值函数</span></h2><p>eg： </p>
<p><img src="/./../images/d35471f1e6cab7e11b2ff38e3d721f95.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<p><img src="/./../images/999125838c56af81d8756c65263e2f8c.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<p><img src="/./../images/fcb1a731c4f4ec18f369f08adaa7363b.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<h2><span id="日期函数">日期函数</span></h2><h3><span id="日期表示"><strong>日期表示:</strong></span></h3><blockquote>
<p>日期-月份-年份  </p>
<p>eg：21-9月-2024</p>
</blockquote>
<h3><span id="函数概述">函数概述：</span></h3><h3><span id="eg">eg:</span></h3><h4><span id="sysdate">sysdate：</span></h4><p><img src="/./../images/17ad51f6237a5327854f372804366892.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<h4><span id="next_day">next_day():</span></h4><h4><span id="last_day"><img src="/./../images/e08719c1055fcb17765d98bc6d3ddb27.png" alt="img"><img src="" alt="点击并拖拽以移动">  last_day():<img src="/./../images/0f022250245f8b0ea4916e0dd82db41e.png" alt="img"><img src="" alt="点击并拖拽以移动"></span></h4><h4><span id="round">round() :</span></h4><h4><span id="add_months"><img src="/./../images/23be81f71051dc1cabc63465775b0bf5.png" alt="img"><img src="" alt="点击并拖拽以移动">  add_months():<img src="/./../images/d8f48457ab44c11cc639dc599fbf072d.png" alt="img"><img src="" alt="点击并拖拽以移动"></span></h4><h4><span id="months_between">months_between():</span></h4><p><img src="/./../images/f50866725db8a186ff28bffa7ee12280.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<h4><span id="extract">extract():</span></h4><p><img src="/./../images/9ad1eaa3306788dd61d99e0128bba509.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<hr>
<h1><span id="约束">约束</span></h1><h2><span id="概念">概念</span></h2><blockquote>
<p>​        约束是作用于表中字段上的规则，用于限制存储在表中的数据</p>
<p>​        约束可以在创建表&#x2F;修改表的时候添加</p>
</blockquote>
<h2><span id="分类">分类</span></h2><table>
<thead>
<tr>
<th>约束</th>
<th>描述</th>
<th>关键字</th>
</tr>
</thead>
<tbody><tr>
<td>非空约束</td>
<td>限制该字段的数据不能为null</td>
<td>not null</td>
</tr>
<tr>
<td>唯一约束</td>
<td>保证该字段的所有数据都是唯一的、不重复的</td>
<td>unique</td>
</tr>
<tr>
<td>主键约束</td>
<td>主键是一行数据的唯一标识，要求非空且唯一</td>
<td>primary key</td>
</tr>
<tr>
<td>默认约束</td>
<td>保存数据时，如果未指定该字段的值，则采用默认值</td>
<td>default</td>
</tr>
<tr>
<td>检查约束</td>
<td>保证字段值满足某一条件</td>
<td>check</td>
</tr>
<tr>
<td>外键约束</td>
<td>用来让两张表的数据之间建立连接，保证数据的一致性和完整性</td>
<td>foreign key</td>
</tr>
</tbody></table>
<p><strong>建表时添加约束：</strong></p>
<p><img src="/./../images/40829ad61cb440a75560116ef1150827.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<p><img src="/./../images/4361af9477a8300dfc31b28afe51f905.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<p> <strong>sql语句添加：</strong></p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">alter table</span> 表名 <span class="keyword">add</span> constraints 约束名称 <span class="keyword">primary key</span>(列名);</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<p><img src="/./../images/c1e4e29e2fd27c6a347a60f6e42df8a0.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<h2><span id="外键约束">外键约束</span></h2><blockquote>
<p><strong>子表（从表）</strong>：具有外键的表</p>
<p><strong>父表（主表）</strong>：外键所关联的表</p>
<p>FOREIGN KEY约束可以与另外一个表的PRIMARY KEY及UNIQUE关联</p>
</blockquote>
<h3><span id="添加外键">添加外键：</span></h3><h4><span id="在创建表的时候添加">在创建表的时候添加：</span></h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">constraint</span> 外键名称 <span class="keyword">foreign key</span>(外键) <span class="keyword">references</span> 表名(外键关联的键)</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<p><img src="/./../images/15280ebfce7b2df8fd7b27dff7e357a2.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">foreign key</span>(列名) <span class="keyword">references</span> 外键关联的表名</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<p><img src="/./../images/dd8465a2c2df1e2ede3033ac36d3c708.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<h4><span id="sql语句添加alter">sql语句添加（alter）：</span></h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">alter table</span> 表名 <span class="keyword">add constraint</span> 外键名称 <span class="keyword">foreign key</span>(列名) <span class="keyword">references</span> 表名(外键关联的键);</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<p><img src="/./../images/95b469abf6c04f1f7729a5e768e0c87f.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<h3><span id="查询外键">查询外键</span></h3><h4><span id="根据外键名称查看外键所在位置">根据外键名称查看外键所在位置：</span></h4><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> <span class="operator">*</span> <span class="keyword">from</span> user_cons_columns cl <span class="keyword">where</span> cl.constraint_name<span class="operator">=</span> <span class="built_in">upper</span>(<span class="string">&#x27;外键名称&#x27;</span>);</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<p><img src="/./../images/59bb57a88e5f365f8eb73c9eab603a71.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<h4><span id="查找表的外键">查找表的外键：</span></h4><p>（包括名称，引用表的表名和对应的列名）</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> <span class="operator">*</span> <span class="keyword">from</span> user_constraints c <span class="keyword">where</span> c.constraint_type<span class="operator">=</span><span class="string">&#x27;R&#x27;</span> <span class="keyword">and</span> c.table_name<span class="operator">=</span><span class="built_in">upper</span>(<span class="string">&#x27;表名&#x27;</span>);</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<p><img src="/./../images/03c84c702efc3edb60fdc407380dd4f1.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<h3><span id="删除外键">删除外键</span></h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">alter table</span> 表名 <span class="keyword">drop</span> <span class="keyword">constraint</span> 外键名称;</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<p><img src="/./../images/e6ca24642a85ab1b2c34b909573e2ab0.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<hr>
<h1><span id="多表查询">多表查询</span></h1><h2><span id="基本概念">基本概念</span></h2><blockquote>
<p><strong>自然连接（内连接）：</strong>左表与右表中每一个元组进行条件匹配，满足条件的才会查询出来</p>
<p><strong>自连接：</strong>同一个表内的查询</p>
<p><strong>外连接：</strong></p>
<ul>
<li>左外连接：左表中的元组不会丢失，即每一个左表中的元素都可查出，若右表没有匹配的，就置为空</li>
<li>右外连接：右表中的元组不会丢失，即每一个右表中的元素都可查出，若左表没有匹配的，就置为空</li>
<li>全连接：左右表的悬浮元组都会加入到最后的查询结果中</li>
</ul>
</blockquote>
<h2><span id="基本结构">基本结构</span></h2><h3><span id="内连接外连接">内连接+外连接：</span></h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> 查询的字段名 <span class="keyword">from</span> 左表 [<span class="keyword">inner</span><span class="operator">|</span><span class="keyword">left</span><span class="operator">|</span><span class="keyword">right</span><span class="operator">|</span><span class="keyword">full</span>] <span class="keyword">join</span> 右表 <span class="keyword">on</span> 连接条件;</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<h3><span id="自连接">自连接：</span></h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> 别名.查询的字段名（列名）<span class="keyword">from</span> 表<span class="number">1</span> 别名<span class="number">1</span>, 表<span class="number">1</span> 别名<span class="number">2</span> <span class="keyword">where</span> 连接条件;</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<h2><span id="关系运算">关系运算</span></h2><p><img src="/./../images/7f967bbc883e1dbeda945687d8bd6cb1.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<h2><span id="大学模式">大学模式：</span></h2><p><img src="/./../images/e0fc8f8f8539bbc29022e483a46d2cea.jpeg" alt="img"><img src="" alt="点击并拖拽以移动"> <img src="/./../images/c7e5a14881782b631e589aa16e3e02e2.jpeg" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<p> <img src="/./../images/8605943ddda38fd8208784f660974792.jpeg" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<p> <img src="/./../images/0582f19eec2c4abba90f7147f044155a.jpeg" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<p> <img src="/./../images/4059de81e3f06c988f800b1a9481d45f.jpeg" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<p> <img src="/./../images/88a754eb7e21b8203df37cbe1b8cc101.jpeg" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<p> <img src="/./../images/809a520c7a01692fb16ca9d1edcfb273.jpeg" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<p> <img src="/./../images/7114e28ca3873c75d96c919a183d8ef7.jpeg" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<p>首先以黑书里面的<a target="_blank" rel="noopener" href="https://db-book.com/">大学模式</a>为例：</p>
<h3><span id="创建基本表结构">创建基本表结构：</span></h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">create table</span> classroom</span><br><span class="line">	(building <span class="type">varchar</span>(<span class="number">15</span>),</span><br><span class="line">	 room_number <span class="type">varchar</span>(<span class="number">7</span>),</span><br><span class="line">	 capacity <span class="type">numeric</span>(<span class="number">4</span>,<span class="number">0</span>),</span><br><span class="line">	 <span class="keyword">primary key</span> (building, room_number)</span><br><span class="line">	);</span><br><span class="line"></span><br><span class="line"><span class="keyword">create table</span> department</span><br><span class="line">	(dept_name <span class="type">varchar</span>(<span class="number">20</span>), </span><br><span class="line">	 building <span class="type">varchar</span>(<span class="number">15</span>), </span><br><span class="line">	 budget <span class="type">numeric</span>(<span class="number">12</span>,<span class="number">2</span>) <span class="keyword">check</span> (budget <span class="operator">&gt;</span> <span class="number">0</span>),</span><br><span class="line">	 <span class="keyword">primary key</span> (dept_name)</span><br><span class="line">	);</span><br><span class="line"></span><br><span class="line"><span class="keyword">create table</span> course</span><br><span class="line">	(course_id <span class="type">varchar</span>(<span class="number">8</span>), </span><br><span class="line">	 title		 	<span class="type">varchar</span>(<span class="number">50</span>), </span><br><span class="line">	 dept_name	 	<span class="type">varchar</span>(<span class="number">20</span>),</span><br><span class="line">	 credits	 	<span class="type">numeric</span>(<span class="number">2</span>,<span class="number">0</span>) <span class="keyword">check</span> (credits <span class="operator">&gt;</span> <span class="number">0</span>),</span><br><span class="line">	 <span class="keyword">primary key</span> (course_id),</span><br><span class="line">	 <span class="keyword">foreign key</span> (dept_name) <span class="keyword">references</span> department (dept_name)</span><br><span class="line">		<span class="keyword">on</span> <span class="keyword">delete</span> <span class="keyword">set</span> <span class="keyword">null</span></span><br><span class="line">	);</span><br><span class="line"></span><br><span class="line"><span class="keyword">create table</span> instructor</span><br><span class="line">	(ID		 	<span class="type">varchar</span>(<span class="number">5</span>), </span><br><span class="line">	 name	 		<span class="type">varchar</span>(<span class="number">20</span>) <span class="keyword">not null</span>, </span><br><span class="line">	 dept_name	 	<span class="type">varchar</span>(<span class="number">20</span>), </span><br><span class="line">	 salary		 	<span class="type">numeric</span>(<span class="number">8</span>,<span class="number">2</span>) <span class="keyword">check</span> (salary <span class="operator">&gt;</span> <span class="number">29000</span>),</span><br><span class="line">	 <span class="keyword">primary key</span> (ID),</span><br><span class="line">	 <span class="keyword">foreign key</span> (dept_name) <span class="keyword">references</span> department (dept_name)</span><br><span class="line">		<span class="keyword">on</span> <span class="keyword">delete</span> <span class="keyword">set</span> <span class="keyword">null</span></span><br><span class="line">	);</span><br><span class="line"></span><br><span class="line"><span class="keyword">create table</span> section</span><br><span class="line">	(course_id	 	<span class="type">varchar</span>(<span class="number">8</span>), </span><br><span class="line">         sec_id	 		<span class="type">varchar</span>(<span class="number">8</span>),</span><br><span class="line">	 semester	 	<span class="type">varchar</span>(<span class="number">6</span>)</span><br><span class="line">		<span class="keyword">check</span> (semester <span class="keyword">in</span> (<span class="string">&#x27;Fall&#x27;</span>, <span class="string">&#x27;Winter&#x27;</span>, <span class="string">&#x27;Spring&#x27;</span>, <span class="string">&#x27;Summer&#x27;</span>)), </span><br><span class="line">	 <span class="keyword">year</span>		 	<span class="type">numeric</span>(<span class="number">4</span>,<span class="number">0</span>) <span class="keyword">check</span> (<span class="keyword">year</span> <span class="operator">&gt;</span> <span class="number">1701</span> <span class="keyword">and</span> <span class="keyword">year</span> <span class="operator">&lt;</span> <span class="number">2100</span>), </span><br><span class="line">	 building	 	<span class="type">varchar</span>(<span class="number">15</span>),</span><br><span class="line">	 room_number 		<span class="type">varchar</span>(<span class="number">7</span>),</span><br><span class="line">	 time_slot_id	 	<span class="type">varchar</span>(<span class="number">4</span>),</span><br><span class="line">	 <span class="keyword">primary key</span> (course_id, sec_id, semester, <span class="keyword">year</span>),</span><br><span class="line">	 <span class="keyword">foreign key</span> (course_id) <span class="keyword">references</span> course (course_id)</span><br><span class="line">		<span class="keyword">on</span> <span class="keyword">delete</span> cascade,</span><br><span class="line">	 <span class="keyword">foreign key</span> (building, room_number) <span class="keyword">references</span> classroom (building, room_number)</span><br><span class="line">		<span class="keyword">on</span> <span class="keyword">delete</span> <span class="keyword">set</span> <span class="keyword">null</span></span><br><span class="line">	);</span><br><span class="line"></span><br><span class="line"><span class="keyword">create table</span> teaches</span><br><span class="line">	(ID		 	<span class="type">varchar</span>(<span class="number">5</span>), </span><br><span class="line">	 course_id	 	<span class="type">varchar</span>(<span class="number">8</span>),</span><br><span class="line">	 sec_id	 		<span class="type">varchar</span>(<span class="number">8</span>), </span><br><span class="line">	 semester	 	<span class="type">varchar</span>(<span class="number">6</span>),</span><br><span class="line">	 <span class="keyword">year</span>		 	<span class="type">numeric</span>(<span class="number">4</span>,<span class="number">0</span>),</span><br><span class="line">	 <span class="keyword">primary key</span> (ID, course_id, sec_id, semester, <span class="keyword">year</span>),</span><br><span class="line">	 <span class="keyword">foreign key</span> (course_id, sec_id, semester, <span class="keyword">year</span>) <span class="keyword">references</span> section (course_id, sec_id, semester, <span class="keyword">year</span>)</span><br><span class="line">		<span class="keyword">on</span> <span class="keyword">delete</span> cascade,</span><br><span class="line">	 <span class="keyword">foreign key</span> (ID) <span class="keyword">references</span> instructor (ID)</span><br><span class="line">		<span class="keyword">on</span> <span class="keyword">delete</span> cascade</span><br><span class="line">	);</span><br><span class="line"></span><br><span class="line"><span class="keyword">create table</span> student</span><br><span class="line">	(ID		  	<span class="type">varchar</span>(<span class="number">5</span>), </span><br><span class="line">	 name		 	<span class="type">varchar</span>(<span class="number">20</span>)  <span class="keyword">not null</span>, </span><br><span class="line">	 dept_name 	 	<span class="type">varchar</span>(<span class="number">20</span>), </span><br><span class="line">	 tot_cred	  	<span class="type">numeric</span>(<span class="number">3</span>,<span class="number">0</span>) <span class="keyword">check</span> (tot_cred <span class="operator">&gt;=</span> <span class="number">0</span>),</span><br><span class="line">	 <span class="keyword">primary key</span> (ID),</span><br><span class="line">	 <span class="keyword">foreign key</span> (dept_name) <span class="keyword">references</span> department (dept_name)</span><br><span class="line">		<span class="keyword">on</span> <span class="keyword">delete</span> <span class="keyword">set</span> <span class="keyword">null</span></span><br><span class="line">	);</span><br><span class="line"></span><br><span class="line"><span class="keyword">create table</span> takes</span><br><span class="line">	(ID		 	<span class="type">varchar</span>(<span class="number">5</span>), </span><br><span class="line">	 course_id	 	<span class="type">varchar</span>(<span class="number">8</span>),</span><br><span class="line">	 sec_id	 		<span class="type">varchar</span>(<span class="number">8</span>), </span><br><span class="line">	 semester	 	<span class="type">varchar</span>(<span class="number">6</span>),</span><br><span class="line">	 <span class="keyword">year</span>		 	<span class="type">numeric</span>(<span class="number">4</span>,<span class="number">0</span>),</span><br><span class="line">	 grade	 	        <span class="type">varchar</span>(<span class="number">2</span>),</span><br><span class="line">	 <span class="keyword">primary key</span> (ID, course_id, sec_id, semester, <span class="keyword">year</span>),</span><br><span class="line">	 <span class="keyword">foreign key</span> (course_id, sec_id, semester, <span class="keyword">year</span>) <span class="keyword">references</span> section (course_id, sec_id, semester, <span class="keyword">year</span>)</span><br><span class="line">		<span class="keyword">on</span> <span class="keyword">delete</span> cascade,</span><br><span class="line">	 <span class="keyword">foreign key</span> (ID) <span class="keyword">references</span> student (ID)</span><br><span class="line">		<span class="keyword">on</span> <span class="keyword">delete</span> cascade</span><br><span class="line">	);</span><br><span class="line"></span><br><span class="line"><span class="keyword">create table</span> advisor</span><br><span class="line">	(s_ID	 	 	<span class="type">varchar</span>(<span class="number">5</span>),</span><br><span class="line">	 i_ID	 		<span class="type">varchar</span>(<span class="number">5</span>),</span><br><span class="line">	 <span class="keyword">primary key</span> (s_ID),</span><br><span class="line">	 <span class="keyword">foreign key</span> (i_ID) <span class="keyword">references</span>  instructor (ID)</span><br><span class="line">		<span class="keyword">on</span> <span class="keyword">delete</span> <span class="keyword">set</span> <span class="keyword">null</span>,</span><br><span class="line">	 <span class="keyword">foreign key</span> (s_ID) <span class="keyword">references</span>  student (ID)</span><br><span class="line">		<span class="keyword">on</span> <span class="keyword">delete</span> cascade</span><br><span class="line">	);</span><br><span class="line"></span><br><span class="line"><span class="keyword">create table</span> time_slot</span><br><span class="line">	(time_slot_id	 	<span class="type">varchar</span>(<span class="number">4</span>),</span><br><span class="line">	 <span class="keyword">day</span>		 	<span class="type">varchar</span>(<span class="number">1</span>),</span><br><span class="line">	 start_hr	 	<span class="type">numeric</span>(<span class="number">2</span>)  <span class="keyword">check</span> (start_hr <span class="operator">&gt;=</span> <span class="number">0</span> <span class="keyword">and</span> start_hr <span class="operator">&lt;</span> <span class="number">24</span>),</span><br><span class="line">	 start_min	 	<span class="type">numeric</span>(<span class="number">2</span>)  <span class="keyword">check</span> (start_min <span class="operator">&gt;=</span> <span class="number">0</span> <span class="keyword">and</span> start_min <span class="operator">&lt;</span> <span class="number">60</span>),</span><br><span class="line">	 end_hr	 		<span class="type">numeric</span>(<span class="number">2</span>)  <span class="keyword">check</span> (end_hr <span class="operator">&gt;=</span> <span class="number">0</span> <span class="keyword">and</span> end_hr <span class="operator">&lt;</span> <span class="number">24</span>),</span><br><span class="line">	 end_min	 	<span class="type">numeric</span>(<span class="number">2</span>)  <span class="keyword">check</span> (end_min <span class="operator">&gt;=</span> <span class="number">0</span> <span class="keyword">and</span> end_min <span class="operator">&lt;</span> <span class="number">60</span>),</span><br><span class="line">	 <span class="keyword">primary key</span> (time_slot_id, <span class="keyword">day</span>, start_hr, start_min)</span><br><span class="line">	);</span><br><span class="line"></span><br><span class="line"><span class="keyword">create table</span> prereq</span><br><span class="line">	(course_id	 	<span class="type">varchar</span>(<span class="number">8</span>), </span><br><span class="line">	 prereq_id	 	<span class="type">varchar</span>(<span class="number">8</span>),</span><br><span class="line">	 <span class="keyword">primary key</span> (course_id, prereq_id),</span><br><span class="line">	 <span class="keyword">foreign key</span> (course_id) <span class="keyword">references</span> course (course_id)</span><br><span class="line">		<span class="keyword">on</span> <span class="keyword">delete</span> cascade,</span><br><span class="line">	 <span class="keyword">foreign key</span> (prereq_id) <span class="keyword">references</span> course (course_id)</span><br><span class="line">	);</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<h3><span id="插入数据">插入数据：</span></h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">delete</span> <span class="keyword">from</span> prereq;</span><br><span class="line"><span class="keyword">delete</span> <span class="keyword">from</span> time_slot;</span><br><span class="line"><span class="keyword">delete</span> <span class="keyword">from</span> advisor;</span><br><span class="line"><span class="keyword">delete</span> <span class="keyword">from</span> takes;</span><br><span class="line"><span class="keyword">delete</span> <span class="keyword">from</span> student;</span><br><span class="line"><span class="keyword">delete</span> <span class="keyword">from</span> teaches;</span><br><span class="line"><span class="keyword">delete</span> <span class="keyword">from</span> section;</span><br><span class="line"><span class="keyword">delete</span> <span class="keyword">from</span> instructor;</span><br><span class="line"><span class="keyword">delete</span> <span class="keyword">from</span> course;</span><br><span class="line"><span class="keyword">delete</span> <span class="keyword">from</span> department;</span><br><span class="line"><span class="keyword">delete</span> <span class="keyword">from</span> classroom;</span><br><span class="line"><span class="keyword">insert into</span> classroom <span class="keyword">values</span> (<span class="string">&#x27;Packard&#x27;</span>, <span class="string">&#x27;101&#x27;</span>, <span class="string">&#x27;500&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> classroom <span class="keyword">values</span> (<span class="string">&#x27;Painter&#x27;</span>, <span class="string">&#x27;514&#x27;</span>, <span class="string">&#x27;10&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> classroom <span class="keyword">values</span> (<span class="string">&#x27;Taylor&#x27;</span>, <span class="string">&#x27;3128&#x27;</span>, <span class="string">&#x27;70&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> classroom <span class="keyword">values</span> (<span class="string">&#x27;Watson&#x27;</span>, <span class="string">&#x27;100&#x27;</span>, <span class="string">&#x27;30&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> classroom <span class="keyword">values</span> (<span class="string">&#x27;Watson&#x27;</span>, <span class="string">&#x27;120&#x27;</span>, <span class="string">&#x27;50&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> department <span class="keyword">values</span> (<span class="string">&#x27;Biology&#x27;</span>, <span class="string">&#x27;Watson&#x27;</span>, <span class="string">&#x27;90000&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> department <span class="keyword">values</span> (<span class="string">&#x27;Comp. Sci.&#x27;</span>, <span class="string">&#x27;Taylor&#x27;</span>, <span class="string">&#x27;100000&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> department <span class="keyword">values</span> (<span class="string">&#x27;Elec. Eng.&#x27;</span>, <span class="string">&#x27;Taylor&#x27;</span>, <span class="string">&#x27;85000&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> department <span class="keyword">values</span> (<span class="string">&#x27;Finance&#x27;</span>, <span class="string">&#x27;Painter&#x27;</span>, <span class="string">&#x27;120000&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> department <span class="keyword">values</span> (<span class="string">&#x27;History&#x27;</span>, <span class="string">&#x27;Painter&#x27;</span>, <span class="string">&#x27;50000&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> department <span class="keyword">values</span> (<span class="string">&#x27;Music&#x27;</span>, <span class="string">&#x27;Packard&#x27;</span>, <span class="string">&#x27;80000&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> department <span class="keyword">values</span> (<span class="string">&#x27;Physics&#x27;</span>, <span class="string">&#x27;Watson&#x27;</span>, <span class="string">&#x27;70000&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> course <span class="keyword">values</span> (<span class="string">&#x27;BIO-101&#x27;</span>, <span class="string">&#x27;Intro. to Biology&#x27;</span>, <span class="string">&#x27;Biology&#x27;</span>, <span class="string">&#x27;4&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> course <span class="keyword">values</span> (<span class="string">&#x27;BIO-301&#x27;</span>, <span class="string">&#x27;Genetics&#x27;</span>, <span class="string">&#x27;Biology&#x27;</span>, <span class="string">&#x27;4&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> course <span class="keyword">values</span> (<span class="string">&#x27;BIO-399&#x27;</span>, <span class="string">&#x27;Computational Biology&#x27;</span>, <span class="string">&#x27;Biology&#x27;</span>, <span class="string">&#x27;3&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> course <span class="keyword">values</span> (<span class="string">&#x27;CS-101&#x27;</span>, <span class="string">&#x27;Intro. to Computer Science&#x27;</span>, <span class="string">&#x27;Comp. Sci.&#x27;</span>, <span class="string">&#x27;4&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> course <span class="keyword">values</span> (<span class="string">&#x27;CS-190&#x27;</span>, <span class="string">&#x27;Game Design&#x27;</span>, <span class="string">&#x27;Comp. Sci.&#x27;</span>, <span class="string">&#x27;4&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> course <span class="keyword">values</span> (<span class="string">&#x27;CS-315&#x27;</span>, <span class="string">&#x27;Robotics&#x27;</span>, <span class="string">&#x27;Comp. Sci.&#x27;</span>, <span class="string">&#x27;3&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> course <span class="keyword">values</span> (<span class="string">&#x27;CS-319&#x27;</span>, <span class="string">&#x27;Image Processing&#x27;</span>, <span class="string">&#x27;Comp. Sci.&#x27;</span>, <span class="string">&#x27;3&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> course <span class="keyword">values</span> (<span class="string">&#x27;CS-347&#x27;</span>, <span class="string">&#x27;Database System Concepts&#x27;</span>, <span class="string">&#x27;Comp. Sci.&#x27;</span>, <span class="string">&#x27;3&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> course <span class="keyword">values</span> (<span class="string">&#x27;EE-181&#x27;</span>, <span class="string">&#x27;Intro. to Digital Systems&#x27;</span>, <span class="string">&#x27;Elec. Eng.&#x27;</span>, <span class="string">&#x27;3&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> course <span class="keyword">values</span> (<span class="string">&#x27;FIN-201&#x27;</span>, <span class="string">&#x27;Investment Banking&#x27;</span>, <span class="string">&#x27;Finance&#x27;</span>, <span class="string">&#x27;3&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> course <span class="keyword">values</span> (<span class="string">&#x27;HIS-351&#x27;</span>, <span class="string">&#x27;World History&#x27;</span>, <span class="string">&#x27;History&#x27;</span>, <span class="string">&#x27;3&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> course <span class="keyword">values</span> (<span class="string">&#x27;MU-199&#x27;</span>, <span class="string">&#x27;Music Video Production&#x27;</span>, <span class="string">&#x27;Music&#x27;</span>, <span class="string">&#x27;3&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> course <span class="keyword">values</span> (<span class="string">&#x27;PHY-101&#x27;</span>, <span class="string">&#x27;Physical Principles&#x27;</span>, <span class="string">&#x27;Physics&#x27;</span>, <span class="string">&#x27;4&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> instructor <span class="keyword">values</span> (<span class="string">&#x27;10101&#x27;</span>, <span class="string">&#x27;Srinivasan&#x27;</span>, <span class="string">&#x27;Comp. Sci.&#x27;</span>, <span class="string">&#x27;65000&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> instructor <span class="keyword">values</span> (<span class="string">&#x27;12121&#x27;</span>, <span class="string">&#x27;Wu&#x27;</span>, <span class="string">&#x27;Finance&#x27;</span>, <span class="string">&#x27;90000&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> instructor <span class="keyword">values</span> (<span class="string">&#x27;15151&#x27;</span>, <span class="string">&#x27;Mozart&#x27;</span>, <span class="string">&#x27;Music&#x27;</span>, <span class="string">&#x27;40000&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> instructor <span class="keyword">values</span> (<span class="string">&#x27;22222&#x27;</span>, <span class="string">&#x27;Einstein&#x27;</span>, <span class="string">&#x27;Physics&#x27;</span>, <span class="string">&#x27;95000&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> instructor <span class="keyword">values</span> (<span class="string">&#x27;32343&#x27;</span>, <span class="string">&#x27;El Said&#x27;</span>, <span class="string">&#x27;History&#x27;</span>, <span class="string">&#x27;60000&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> instructor <span class="keyword">values</span> (<span class="string">&#x27;33456&#x27;</span>, <span class="string">&#x27;Gold&#x27;</span>, <span class="string">&#x27;Physics&#x27;</span>, <span class="string">&#x27;87000&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> instructor <span class="keyword">values</span> (<span class="string">&#x27;45565&#x27;</span>, <span class="string">&#x27;Katz&#x27;</span>, <span class="string">&#x27;Comp. Sci.&#x27;</span>, <span class="string">&#x27;75000&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> instructor <span class="keyword">values</span> (<span class="string">&#x27;58583&#x27;</span>, <span class="string">&#x27;Califieri&#x27;</span>, <span class="string">&#x27;History&#x27;</span>, <span class="string">&#x27;62000&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> instructor <span class="keyword">values</span> (<span class="string">&#x27;76543&#x27;</span>, <span class="string">&#x27;Singh&#x27;</span>, <span class="string">&#x27;Finance&#x27;</span>, <span class="string">&#x27;80000&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> instructor <span class="keyword">values</span> (<span class="string">&#x27;76766&#x27;</span>, <span class="string">&#x27;Crick&#x27;</span>, <span class="string">&#x27;Biology&#x27;</span>, <span class="string">&#x27;72000&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> instructor <span class="keyword">values</span> (<span class="string">&#x27;83821&#x27;</span>, <span class="string">&#x27;Brandt&#x27;</span>, <span class="string">&#x27;Comp. Sci.&#x27;</span>, <span class="string">&#x27;92000&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> instructor <span class="keyword">values</span> (<span class="string">&#x27;98345&#x27;</span>, <span class="string">&#x27;Kim&#x27;</span>, <span class="string">&#x27;Elec. Eng.&#x27;</span>, <span class="string">&#x27;80000&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> section <span class="keyword">values</span> (<span class="string">&#x27;BIO-101&#x27;</span>, <span class="string">&#x27;1&#x27;</span>, <span class="string">&#x27;Summer&#x27;</span>, <span class="string">&#x27;2017&#x27;</span>, <span class="string">&#x27;Painter&#x27;</span>, <span class="string">&#x27;514&#x27;</span>, <span class="string">&#x27;B&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> section <span class="keyword">values</span> (<span class="string">&#x27;BIO-301&#x27;</span>, <span class="string">&#x27;1&#x27;</span>, <span class="string">&#x27;Summer&#x27;</span>, <span class="string">&#x27;2018&#x27;</span>, <span class="string">&#x27;Painter&#x27;</span>, <span class="string">&#x27;514&#x27;</span>, <span class="string">&#x27;A&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> section <span class="keyword">values</span> (<span class="string">&#x27;CS-101&#x27;</span>, <span class="string">&#x27;1&#x27;</span>, <span class="string">&#x27;Fall&#x27;</span>, <span class="string">&#x27;2017&#x27;</span>, <span class="string">&#x27;Packard&#x27;</span>, <span class="string">&#x27;101&#x27;</span>, <span class="string">&#x27;H&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> section <span class="keyword">values</span> (<span class="string">&#x27;CS-101&#x27;</span>, <span class="string">&#x27;1&#x27;</span>, <span class="string">&#x27;Spring&#x27;</span>, <span class="string">&#x27;2018&#x27;</span>, <span class="string">&#x27;Packard&#x27;</span>, <span class="string">&#x27;101&#x27;</span>, <span class="string">&#x27;F&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> section <span class="keyword">values</span> (<span class="string">&#x27;CS-190&#x27;</span>, <span class="string">&#x27;1&#x27;</span>, <span class="string">&#x27;Spring&#x27;</span>, <span class="string">&#x27;2017&#x27;</span>, <span class="string">&#x27;Taylor&#x27;</span>, <span class="string">&#x27;3128&#x27;</span>, <span class="string">&#x27;E&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> section <span class="keyword">values</span> (<span class="string">&#x27;CS-190&#x27;</span>, <span class="string">&#x27;2&#x27;</span>, <span class="string">&#x27;Spring&#x27;</span>, <span class="string">&#x27;2017&#x27;</span>, <span class="string">&#x27;Taylor&#x27;</span>, <span class="string">&#x27;3128&#x27;</span>, <span class="string">&#x27;A&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> section <span class="keyword">values</span> (<span class="string">&#x27;CS-315&#x27;</span>, <span class="string">&#x27;1&#x27;</span>, <span class="string">&#x27;Spring&#x27;</span>, <span class="string">&#x27;2018&#x27;</span>, <span class="string">&#x27;Watson&#x27;</span>, <span class="string">&#x27;120&#x27;</span>, <span class="string">&#x27;D&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> section <span class="keyword">values</span> (<span class="string">&#x27;CS-319&#x27;</span>, <span class="string">&#x27;1&#x27;</span>, <span class="string">&#x27;Spring&#x27;</span>, <span class="string">&#x27;2018&#x27;</span>, <span class="string">&#x27;Watson&#x27;</span>, <span class="string">&#x27;100&#x27;</span>, <span class="string">&#x27;B&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> section <span class="keyword">values</span> (<span class="string">&#x27;CS-319&#x27;</span>, <span class="string">&#x27;2&#x27;</span>, <span class="string">&#x27;Spring&#x27;</span>, <span class="string">&#x27;2018&#x27;</span>, <span class="string">&#x27;Taylor&#x27;</span>, <span class="string">&#x27;3128&#x27;</span>, <span class="string">&#x27;C&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> section <span class="keyword">values</span> (<span class="string">&#x27;CS-347&#x27;</span>, <span class="string">&#x27;1&#x27;</span>, <span class="string">&#x27;Fall&#x27;</span>, <span class="string">&#x27;2017&#x27;</span>, <span class="string">&#x27;Taylor&#x27;</span>, <span class="string">&#x27;3128&#x27;</span>, <span class="string">&#x27;A&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> section <span class="keyword">values</span> (<span class="string">&#x27;EE-181&#x27;</span>, <span class="string">&#x27;1&#x27;</span>, <span class="string">&#x27;Spring&#x27;</span>, <span class="string">&#x27;2017&#x27;</span>, <span class="string">&#x27;Taylor&#x27;</span>, <span class="string">&#x27;3128&#x27;</span>, <span class="string">&#x27;C&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> section <span class="keyword">values</span> (<span class="string">&#x27;FIN-201&#x27;</span>, <span class="string">&#x27;1&#x27;</span>, <span class="string">&#x27;Spring&#x27;</span>, <span class="string">&#x27;2018&#x27;</span>, <span class="string">&#x27;Packard&#x27;</span>, <span class="string">&#x27;101&#x27;</span>, <span class="string">&#x27;B&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> section <span class="keyword">values</span> (<span class="string">&#x27;HIS-351&#x27;</span>, <span class="string">&#x27;1&#x27;</span>, <span class="string">&#x27;Spring&#x27;</span>, <span class="string">&#x27;2018&#x27;</span>, <span class="string">&#x27;Painter&#x27;</span>, <span class="string">&#x27;514&#x27;</span>, <span class="string">&#x27;C&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> section <span class="keyword">values</span> (<span class="string">&#x27;MU-199&#x27;</span>, <span class="string">&#x27;1&#x27;</span>, <span class="string">&#x27;Spring&#x27;</span>, <span class="string">&#x27;2018&#x27;</span>, <span class="string">&#x27;Packard&#x27;</span>, <span class="string">&#x27;101&#x27;</span>, <span class="string">&#x27;D&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> section <span class="keyword">values</span> (<span class="string">&#x27;PHY-101&#x27;</span>, <span class="string">&#x27;1&#x27;</span>, <span class="string">&#x27;Fall&#x27;</span>, <span class="string">&#x27;2017&#x27;</span>, <span class="string">&#x27;Watson&#x27;</span>, <span class="string">&#x27;100&#x27;</span>, <span class="string">&#x27;A&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> teaches <span class="keyword">values</span> (<span class="string">&#x27;10101&#x27;</span>, <span class="string">&#x27;CS-101&#x27;</span>, <span class="string">&#x27;1&#x27;</span>, <span class="string">&#x27;Fall&#x27;</span>, <span class="string">&#x27;2017&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> teaches <span class="keyword">values</span> (<span class="string">&#x27;10101&#x27;</span>, <span class="string">&#x27;CS-315&#x27;</span>, <span class="string">&#x27;1&#x27;</span>, <span class="string">&#x27;Spring&#x27;</span>, <span class="string">&#x27;2018&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> teaches <span class="keyword">values</span> (<span class="string">&#x27;10101&#x27;</span>, <span class="string">&#x27;CS-347&#x27;</span>, <span class="string">&#x27;1&#x27;</span>, <span class="string">&#x27;Fall&#x27;</span>, <span class="string">&#x27;2017&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> teaches <span class="keyword">values</span> (<span class="string">&#x27;12121&#x27;</span>, <span class="string">&#x27;FIN-201&#x27;</span>, <span class="string">&#x27;1&#x27;</span>, <span class="string">&#x27;Spring&#x27;</span>, <span class="string">&#x27;2018&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> teaches <span class="keyword">values</span> (<span class="string">&#x27;15151&#x27;</span>, <span class="string">&#x27;MU-199&#x27;</span>, <span class="string">&#x27;1&#x27;</span>, <span class="string">&#x27;Spring&#x27;</span>, <span class="string">&#x27;2018&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> teaches <span class="keyword">values</span> (<span class="string">&#x27;22222&#x27;</span>, <span class="string">&#x27;PHY-101&#x27;</span>, <span class="string">&#x27;1&#x27;</span>, <span class="string">&#x27;Fall&#x27;</span>, <span class="string">&#x27;2017&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> teaches <span class="keyword">values</span> (<span class="string">&#x27;32343&#x27;</span>, <span class="string">&#x27;HIS-351&#x27;</span>, <span class="string">&#x27;1&#x27;</span>, <span class="string">&#x27;Spring&#x27;</span>, <span class="string">&#x27;2018&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> teaches <span class="keyword">values</span> (<span class="string">&#x27;45565&#x27;</span>, <span class="string">&#x27;CS-101&#x27;</span>, <span class="string">&#x27;1&#x27;</span>, <span class="string">&#x27;Spring&#x27;</span>, <span class="string">&#x27;2018&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> teaches <span class="keyword">values</span> (<span class="string">&#x27;45565&#x27;</span>, <span class="string">&#x27;CS-319&#x27;</span>, <span class="string">&#x27;1&#x27;</span>, <span class="string">&#x27;Spring&#x27;</span>, <span class="string">&#x27;2018&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> teaches <span class="keyword">values</span> (<span class="string">&#x27;76766&#x27;</span>, <span class="string">&#x27;BIO-101&#x27;</span>, <span class="string">&#x27;1&#x27;</span>, <span class="string">&#x27;Summer&#x27;</span>, <span class="string">&#x27;2017&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> teaches <span class="keyword">values</span> (<span class="string">&#x27;76766&#x27;</span>, <span class="string">&#x27;BIO-301&#x27;</span>, <span class="string">&#x27;1&#x27;</span>, <span class="string">&#x27;Summer&#x27;</span>, <span class="string">&#x27;2018&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> teaches <span class="keyword">values</span> (<span class="string">&#x27;83821&#x27;</span>, <span class="string">&#x27;CS-190&#x27;</span>, <span class="string">&#x27;1&#x27;</span>, <span class="string">&#x27;Spring&#x27;</span>, <span class="string">&#x27;2017&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> teaches <span class="keyword">values</span> (<span class="string">&#x27;83821&#x27;</span>, <span class="string">&#x27;CS-190&#x27;</span>, <span class="string">&#x27;2&#x27;</span>, <span class="string">&#x27;Spring&#x27;</span>, <span class="string">&#x27;2017&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> teaches <span class="keyword">values</span> (<span class="string">&#x27;83821&#x27;</span>, <span class="string">&#x27;CS-319&#x27;</span>, <span class="string">&#x27;2&#x27;</span>, <span class="string">&#x27;Spring&#x27;</span>, <span class="string">&#x27;2018&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> teaches <span class="keyword">values</span> (<span class="string">&#x27;98345&#x27;</span>, <span class="string">&#x27;EE-181&#x27;</span>, <span class="string">&#x27;1&#x27;</span>, <span class="string">&#x27;Spring&#x27;</span>, <span class="string">&#x27;2017&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> student <span class="keyword">values</span> (<span class="string">&#x27;00128&#x27;</span>, <span class="string">&#x27;Zhang&#x27;</span>, <span class="string">&#x27;Comp. Sci.&#x27;</span>, <span class="string">&#x27;102&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> student <span class="keyword">values</span> (<span class="string">&#x27;12345&#x27;</span>, <span class="string">&#x27;Shankar&#x27;</span>, <span class="string">&#x27;Comp. Sci.&#x27;</span>, <span class="string">&#x27;32&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> student <span class="keyword">values</span> (<span class="string">&#x27;19991&#x27;</span>, <span class="string">&#x27;Brandt&#x27;</span>, <span class="string">&#x27;History&#x27;</span>, <span class="string">&#x27;80&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> student <span class="keyword">values</span> (<span class="string">&#x27;23121&#x27;</span>, <span class="string">&#x27;Chavez&#x27;</span>, <span class="string">&#x27;Finance&#x27;</span>, <span class="string">&#x27;110&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> student <span class="keyword">values</span> (<span class="string">&#x27;44553&#x27;</span>, <span class="string">&#x27;Peltier&#x27;</span>, <span class="string">&#x27;Physics&#x27;</span>, <span class="string">&#x27;56&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> student <span class="keyword">values</span> (<span class="string">&#x27;45678&#x27;</span>, <span class="string">&#x27;Levy&#x27;</span>, <span class="string">&#x27;Physics&#x27;</span>, <span class="string">&#x27;46&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> student <span class="keyword">values</span> (<span class="string">&#x27;54321&#x27;</span>, <span class="string">&#x27;Williams&#x27;</span>, <span class="string">&#x27;Comp. Sci.&#x27;</span>, <span class="string">&#x27;54&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> student <span class="keyword">values</span> (<span class="string">&#x27;55739&#x27;</span>, <span class="string">&#x27;Sanchez&#x27;</span>, <span class="string">&#x27;Music&#x27;</span>, <span class="string">&#x27;38&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> student <span class="keyword">values</span> (<span class="string">&#x27;70557&#x27;</span>, <span class="string">&#x27;Snow&#x27;</span>, <span class="string">&#x27;Physics&#x27;</span>, <span class="string">&#x27;0&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> student <span class="keyword">values</span> (<span class="string">&#x27;76543&#x27;</span>, <span class="string">&#x27;Brown&#x27;</span>, <span class="string">&#x27;Comp. Sci.&#x27;</span>, <span class="string">&#x27;58&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> student <span class="keyword">values</span> (<span class="string">&#x27;76653&#x27;</span>, <span class="string">&#x27;Aoi&#x27;</span>, <span class="string">&#x27;Elec. Eng.&#x27;</span>, <span class="string">&#x27;60&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> student <span class="keyword">values</span> (<span class="string">&#x27;98765&#x27;</span>, <span class="string">&#x27;Bourikas&#x27;</span>, <span class="string">&#x27;Elec. Eng.&#x27;</span>, <span class="string">&#x27;98&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> student <span class="keyword">values</span> (<span class="string">&#x27;98988&#x27;</span>, <span class="string">&#x27;Tanaka&#x27;</span>, <span class="string">&#x27;Biology&#x27;</span>, <span class="string">&#x27;120&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> takes <span class="keyword">values</span> (<span class="string">&#x27;00128&#x27;</span>, <span class="string">&#x27;CS-101&#x27;</span>, <span class="string">&#x27;1&#x27;</span>, <span class="string">&#x27;Fall&#x27;</span>, <span class="string">&#x27;2017&#x27;</span>, <span class="string">&#x27;A&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> takes <span class="keyword">values</span> (<span class="string">&#x27;00128&#x27;</span>, <span class="string">&#x27;CS-347&#x27;</span>, <span class="string">&#x27;1&#x27;</span>, <span class="string">&#x27;Fall&#x27;</span>, <span class="string">&#x27;2017&#x27;</span>, <span class="string">&#x27;A-&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> takes <span class="keyword">values</span> (<span class="string">&#x27;12345&#x27;</span>, <span class="string">&#x27;CS-101&#x27;</span>, <span class="string">&#x27;1&#x27;</span>, <span class="string">&#x27;Fall&#x27;</span>, <span class="string">&#x27;2017&#x27;</span>, <span class="string">&#x27;C&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> takes <span class="keyword">values</span> (<span class="string">&#x27;12345&#x27;</span>, <span class="string">&#x27;CS-190&#x27;</span>, <span class="string">&#x27;2&#x27;</span>, <span class="string">&#x27;Spring&#x27;</span>, <span class="string">&#x27;2017&#x27;</span>, <span class="string">&#x27;A&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> takes <span class="keyword">values</span> (<span class="string">&#x27;12345&#x27;</span>, <span class="string">&#x27;CS-315&#x27;</span>, <span class="string">&#x27;1&#x27;</span>, <span class="string">&#x27;Spring&#x27;</span>, <span class="string">&#x27;2018&#x27;</span>, <span class="string">&#x27;A&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> takes <span class="keyword">values</span> (<span class="string">&#x27;12345&#x27;</span>, <span class="string">&#x27;CS-347&#x27;</span>, <span class="string">&#x27;1&#x27;</span>, <span class="string">&#x27;Fall&#x27;</span>, <span class="string">&#x27;2017&#x27;</span>, <span class="string">&#x27;A&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> takes <span class="keyword">values</span> (<span class="string">&#x27;19991&#x27;</span>, <span class="string">&#x27;HIS-351&#x27;</span>, <span class="string">&#x27;1&#x27;</span>, <span class="string">&#x27;Spring&#x27;</span>, <span class="string">&#x27;2018&#x27;</span>, <span class="string">&#x27;B&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> takes <span class="keyword">values</span> (<span class="string">&#x27;23121&#x27;</span>, <span class="string">&#x27;FIN-201&#x27;</span>, <span class="string">&#x27;1&#x27;</span>, <span class="string">&#x27;Spring&#x27;</span>, <span class="string">&#x27;2018&#x27;</span>, <span class="string">&#x27;C+&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> takes <span class="keyword">values</span> (<span class="string">&#x27;44553&#x27;</span>, <span class="string">&#x27;PHY-101&#x27;</span>, <span class="string">&#x27;1&#x27;</span>, <span class="string">&#x27;Fall&#x27;</span>, <span class="string">&#x27;2017&#x27;</span>, <span class="string">&#x27;B-&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> takes <span class="keyword">values</span> (<span class="string">&#x27;45678&#x27;</span>, <span class="string">&#x27;CS-101&#x27;</span>, <span class="string">&#x27;1&#x27;</span>, <span class="string">&#x27;Fall&#x27;</span>, <span class="string">&#x27;2017&#x27;</span>, <span class="string">&#x27;F&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> takes <span class="keyword">values</span> (<span class="string">&#x27;45678&#x27;</span>, <span class="string">&#x27;CS-101&#x27;</span>, <span class="string">&#x27;1&#x27;</span>, <span class="string">&#x27;Spring&#x27;</span>, <span class="string">&#x27;2018&#x27;</span>, <span class="string">&#x27;B+&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> takes <span class="keyword">values</span> (<span class="string">&#x27;45678&#x27;</span>, <span class="string">&#x27;CS-319&#x27;</span>, <span class="string">&#x27;1&#x27;</span>, <span class="string">&#x27;Spring&#x27;</span>, <span class="string">&#x27;2018&#x27;</span>, <span class="string">&#x27;B&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> takes <span class="keyword">values</span> (<span class="string">&#x27;54321&#x27;</span>, <span class="string">&#x27;CS-101&#x27;</span>, <span class="string">&#x27;1&#x27;</span>, <span class="string">&#x27;Fall&#x27;</span>, <span class="string">&#x27;2017&#x27;</span>, <span class="string">&#x27;A-&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> takes <span class="keyword">values</span> (<span class="string">&#x27;54321&#x27;</span>, <span class="string">&#x27;CS-190&#x27;</span>, <span class="string">&#x27;2&#x27;</span>, <span class="string">&#x27;Spring&#x27;</span>, <span class="string">&#x27;2017&#x27;</span>, <span class="string">&#x27;B+&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> takes <span class="keyword">values</span> (<span class="string">&#x27;55739&#x27;</span>, <span class="string">&#x27;MU-199&#x27;</span>, <span class="string">&#x27;1&#x27;</span>, <span class="string">&#x27;Spring&#x27;</span>, <span class="string">&#x27;2018&#x27;</span>, <span class="string">&#x27;A-&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> takes <span class="keyword">values</span> (<span class="string">&#x27;76543&#x27;</span>, <span class="string">&#x27;CS-101&#x27;</span>, <span class="string">&#x27;1&#x27;</span>, <span class="string">&#x27;Fall&#x27;</span>, <span class="string">&#x27;2017&#x27;</span>, <span class="string">&#x27;A&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> takes <span class="keyword">values</span> (<span class="string">&#x27;76543&#x27;</span>, <span class="string">&#x27;CS-319&#x27;</span>, <span class="string">&#x27;2&#x27;</span>, <span class="string">&#x27;Spring&#x27;</span>, <span class="string">&#x27;2018&#x27;</span>, <span class="string">&#x27;A&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> takes <span class="keyword">values</span> (<span class="string">&#x27;76653&#x27;</span>, <span class="string">&#x27;EE-181&#x27;</span>, <span class="string">&#x27;1&#x27;</span>, <span class="string">&#x27;Spring&#x27;</span>, <span class="string">&#x27;2017&#x27;</span>, <span class="string">&#x27;C&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> takes <span class="keyword">values</span> (<span class="string">&#x27;98765&#x27;</span>, <span class="string">&#x27;CS-101&#x27;</span>, <span class="string">&#x27;1&#x27;</span>, <span class="string">&#x27;Fall&#x27;</span>, <span class="string">&#x27;2017&#x27;</span>, <span class="string">&#x27;C-&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> takes <span class="keyword">values</span> (<span class="string">&#x27;98765&#x27;</span>, <span class="string">&#x27;CS-315&#x27;</span>, <span class="string">&#x27;1&#x27;</span>, <span class="string">&#x27;Spring&#x27;</span>, <span class="string">&#x27;2018&#x27;</span>, <span class="string">&#x27;B&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> takes <span class="keyword">values</span> (<span class="string">&#x27;98988&#x27;</span>, <span class="string">&#x27;BIO-101&#x27;</span>, <span class="string">&#x27;1&#x27;</span>, <span class="string">&#x27;Summer&#x27;</span>, <span class="string">&#x27;2017&#x27;</span>, <span class="string">&#x27;A&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> takes <span class="keyword">values</span> (<span class="string">&#x27;98988&#x27;</span>, <span class="string">&#x27;BIO-301&#x27;</span>, <span class="string">&#x27;1&#x27;</span>, <span class="string">&#x27;Summer&#x27;</span>, <span class="string">&#x27;2018&#x27;</span>, <span class="keyword">null</span>);</span><br><span class="line"><span class="keyword">insert into</span> advisor <span class="keyword">values</span> (<span class="string">&#x27;00128&#x27;</span>, <span class="string">&#x27;45565&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> advisor <span class="keyword">values</span> (<span class="string">&#x27;12345&#x27;</span>, <span class="string">&#x27;10101&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> advisor <span class="keyword">values</span> (<span class="string">&#x27;23121&#x27;</span>, <span class="string">&#x27;76543&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> advisor <span class="keyword">values</span> (<span class="string">&#x27;44553&#x27;</span>, <span class="string">&#x27;22222&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> advisor <span class="keyword">values</span> (<span class="string">&#x27;45678&#x27;</span>, <span class="string">&#x27;22222&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> advisor <span class="keyword">values</span> (<span class="string">&#x27;76543&#x27;</span>, <span class="string">&#x27;45565&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> advisor <span class="keyword">values</span> (<span class="string">&#x27;76653&#x27;</span>, <span class="string">&#x27;98345&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> advisor <span class="keyword">values</span> (<span class="string">&#x27;98765&#x27;</span>, <span class="string">&#x27;98345&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> advisor <span class="keyword">values</span> (<span class="string">&#x27;98988&#x27;</span>, <span class="string">&#x27;76766&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> time_slot <span class="keyword">values</span> (<span class="string">&#x27;A&#x27;</span>, <span class="string">&#x27;M&#x27;</span>, <span class="string">&#x27;8&#x27;</span>, <span class="string">&#x27;0&#x27;</span>, <span class="string">&#x27;8&#x27;</span>, <span class="string">&#x27;50&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> time_slot <span class="keyword">values</span> (<span class="string">&#x27;A&#x27;</span>, <span class="string">&#x27;W&#x27;</span>, <span class="string">&#x27;8&#x27;</span>, <span class="string">&#x27;0&#x27;</span>, <span class="string">&#x27;8&#x27;</span>, <span class="string">&#x27;50&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> time_slot <span class="keyword">values</span> (<span class="string">&#x27;A&#x27;</span>, <span class="string">&#x27;F&#x27;</span>, <span class="string">&#x27;8&#x27;</span>, <span class="string">&#x27;0&#x27;</span>, <span class="string">&#x27;8&#x27;</span>, <span class="string">&#x27;50&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> time_slot <span class="keyword">values</span> (<span class="string">&#x27;B&#x27;</span>, <span class="string">&#x27;M&#x27;</span>, <span class="string">&#x27;9&#x27;</span>, <span class="string">&#x27;0&#x27;</span>, <span class="string">&#x27;9&#x27;</span>, <span class="string">&#x27;50&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> time_slot <span class="keyword">values</span> (<span class="string">&#x27;B&#x27;</span>, <span class="string">&#x27;W&#x27;</span>, <span class="string">&#x27;9&#x27;</span>, <span class="string">&#x27;0&#x27;</span>, <span class="string">&#x27;9&#x27;</span>, <span class="string">&#x27;50&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> time_slot <span class="keyword">values</span> (<span class="string">&#x27;B&#x27;</span>, <span class="string">&#x27;F&#x27;</span>, <span class="string">&#x27;9&#x27;</span>, <span class="string">&#x27;0&#x27;</span>, <span class="string">&#x27;9&#x27;</span>, <span class="string">&#x27;50&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> time_slot <span class="keyword">values</span> (<span class="string">&#x27;C&#x27;</span>, <span class="string">&#x27;M&#x27;</span>, <span class="string">&#x27;11&#x27;</span>, <span class="string">&#x27;0&#x27;</span>, <span class="string">&#x27;11&#x27;</span>, <span class="string">&#x27;50&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> time_slot <span class="keyword">values</span> (<span class="string">&#x27;C&#x27;</span>, <span class="string">&#x27;W&#x27;</span>, <span class="string">&#x27;11&#x27;</span>, <span class="string">&#x27;0&#x27;</span>, <span class="string">&#x27;11&#x27;</span>, <span class="string">&#x27;50&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> time_slot <span class="keyword">values</span> (<span class="string">&#x27;C&#x27;</span>, <span class="string">&#x27;F&#x27;</span>, <span class="string">&#x27;11&#x27;</span>, <span class="string">&#x27;0&#x27;</span>, <span class="string">&#x27;11&#x27;</span>, <span class="string">&#x27;50&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> time_slot <span class="keyword">values</span> (<span class="string">&#x27;D&#x27;</span>, <span class="string">&#x27;M&#x27;</span>, <span class="string">&#x27;13&#x27;</span>, <span class="string">&#x27;0&#x27;</span>, <span class="string">&#x27;13&#x27;</span>, <span class="string">&#x27;50&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> time_slot <span class="keyword">values</span> (<span class="string">&#x27;D&#x27;</span>, <span class="string">&#x27;W&#x27;</span>, <span class="string">&#x27;13&#x27;</span>, <span class="string">&#x27;0&#x27;</span>, <span class="string">&#x27;13&#x27;</span>, <span class="string">&#x27;50&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> time_slot <span class="keyword">values</span> (<span class="string">&#x27;D&#x27;</span>, <span class="string">&#x27;F&#x27;</span>, <span class="string">&#x27;13&#x27;</span>, <span class="string">&#x27;0&#x27;</span>, <span class="string">&#x27;13&#x27;</span>, <span class="string">&#x27;50&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> time_slot <span class="keyword">values</span> (<span class="string">&#x27;E&#x27;</span>, <span class="string">&#x27;T&#x27;</span>, <span class="string">&#x27;10&#x27;</span>, <span class="string">&#x27;30&#x27;</span>, <span class="string">&#x27;11&#x27;</span>, <span class="string">&#x27;45 &#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> time_slot <span class="keyword">values</span> (<span class="string">&#x27;E&#x27;</span>, <span class="string">&#x27;R&#x27;</span>, <span class="string">&#x27;10&#x27;</span>, <span class="string">&#x27;30&#x27;</span>, <span class="string">&#x27;11&#x27;</span>, <span class="string">&#x27;45 &#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> time_slot <span class="keyword">values</span> (<span class="string">&#x27;F&#x27;</span>, <span class="string">&#x27;T&#x27;</span>, <span class="string">&#x27;14&#x27;</span>, <span class="string">&#x27;30&#x27;</span>, <span class="string">&#x27;15&#x27;</span>, <span class="string">&#x27;45 &#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> time_slot <span class="keyword">values</span> (<span class="string">&#x27;F&#x27;</span>, <span class="string">&#x27;R&#x27;</span>, <span class="string">&#x27;14&#x27;</span>, <span class="string">&#x27;30&#x27;</span>, <span class="string">&#x27;15&#x27;</span>, <span class="string">&#x27;45 &#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> time_slot <span class="keyword">values</span> (<span class="string">&#x27;G&#x27;</span>, <span class="string">&#x27;M&#x27;</span>, <span class="string">&#x27;16&#x27;</span>, <span class="string">&#x27;0&#x27;</span>, <span class="string">&#x27;16&#x27;</span>, <span class="string">&#x27;50&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> time_slot <span class="keyword">values</span> (<span class="string">&#x27;G&#x27;</span>, <span class="string">&#x27;W&#x27;</span>, <span class="string">&#x27;16&#x27;</span>, <span class="string">&#x27;0&#x27;</span>, <span class="string">&#x27;16&#x27;</span>, <span class="string">&#x27;50&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> time_slot <span class="keyword">values</span> (<span class="string">&#x27;G&#x27;</span>, <span class="string">&#x27;F&#x27;</span>, <span class="string">&#x27;16&#x27;</span>, <span class="string">&#x27;0&#x27;</span>, <span class="string">&#x27;16&#x27;</span>, <span class="string">&#x27;50&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> time_slot <span class="keyword">values</span> (<span class="string">&#x27;H&#x27;</span>, <span class="string">&#x27;W&#x27;</span>, <span class="string">&#x27;10&#x27;</span>, <span class="string">&#x27;0&#x27;</span>, <span class="string">&#x27;12&#x27;</span>, <span class="string">&#x27;30&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> prereq <span class="keyword">values</span> (<span class="string">&#x27;BIO-301&#x27;</span>, <span class="string">&#x27;BIO-101&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> prereq <span class="keyword">values</span> (<span class="string">&#x27;BIO-399&#x27;</span>, <span class="string">&#x27;BIO-101&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> prereq <span class="keyword">values</span> (<span class="string">&#x27;CS-190&#x27;</span>, <span class="string">&#x27;CS-101&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> prereq <span class="keyword">values</span> (<span class="string">&#x27;CS-315&#x27;</span>, <span class="string">&#x27;CS-101&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> prereq <span class="keyword">values</span> (<span class="string">&#x27;CS-319&#x27;</span>, <span class="string">&#x27;CS-101&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> prereq <span class="keyword">values</span> (<span class="string">&#x27;CS-347&#x27;</span>, <span class="string">&#x27;CS-101&#x27;</span>);</span><br><span class="line"><span class="keyword">insert into</span> prereq <span class="keyword">values</span> (<span class="string">&#x27;EE-181&#x27;</span>, <span class="string">&#x27;PHY-101&#x27;</span>);</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<h2><span id="内连接-自然连接">内连接 （自然连接）</span></h2><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> 查询的字段（列名）<span class="keyword">from</span> 左表 <span class="keyword">inner</span> <span class="keyword">join</span> 右边 <span class="keyword">on</span> 连接条件;</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<p><img src="/./../images/53212883411440b6c476354688598089.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<h2><span id="外连接">外连接</span></h2><h3><span id="左外连接">左外连接</span></h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> 查询的字段名（列名）<span class="keyword">from</span> 左表 <span class="keyword">left</span> <span class="keyword">join</span> 右表 <span class="keyword">on</span> 连接条件;</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<h2><span id><img src="/./../images/15d70b19a53e84723c86870af92d60ce.png" alt="img"><img src="" alt="点击并拖拽以移动"></span></h2><h3><span id="右外连接">右外连接</span></h3><h2><span id><img src="/./../images/e2545ef8dfe819b25711e6ca4d9d1519.png" alt="img"><img src="" alt="点击并拖拽以移动"></span></h2><h3><span id="全连接">全连接</span></h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> 查询出的字段名（列名） <span class="keyword">from</span> 左表 <span class="keyword">full</span> <span class="keyword">join</span> 右表 <span class="keyword">on</span> 连接条件;</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<p><img src="/./../images/d4f47a3733ffb6efc263550d72f979fe.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<h2><span id="自连接">自连接</span></h2><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">select</span> 别名.查询的字段名（列名）<span class="keyword">from</span> 表<span class="number">1</span> 别名<span class="number">1</span>, 表<span class="number">1</span> 别名<span class="number">2</span> <span class="keyword">where</span> 连接条件;</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<h2><span id><img src="/./../images/4ecfafa24c16d6298db3985d7953512c.png" alt="img"><img src="" alt="点击并拖拽以移动"></span></h2><hr>
<h1><span id="视图">视图</span></h1><h2><span id="基本概念">基本概念</span></h2><blockquote>
<ol>
<li>视图是一个虚拟表，视图不在数据库中存储数据，视图的行和列来自于子查询所返回的结果</li>
<li>视图名不允许与基本表重名</li>
<li>可以通过视图对数据进行增删改查：insert、delete、select</li>
<li>基本表中的数据改变时，视图中的数据也会动态更新</li>
</ol>
</blockquote>
<h2><span id="基本操作">基本操作</span></h2><h3><span id="查看视图">查看视图</span></h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">desc</span> Vcourse;</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<p><img src="/./../images/acd5e779356e0606b132ba64e3b1dc42.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<h3><span id="创建视图">创建视图</span></h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">create</span> [<span class="keyword">or</span> replace] [&#123;force<span class="operator">|</span>noforce&#125;] <span class="keyword">view</span> 视图名(别名列表) <span class="keyword">as</span> 子查询;</span><br><span class="line"><span class="comment">--or replace:如果视图已存在，则用新视图替换旧视图</span></span><br><span class="line"><span class="comment">--force:基本表不存在，也可以创建视图，但是创建的视图不能正常使用</span></span><br><span class="line"><span class="comment">--noforce:基本表不存在，不能创建视图</span></span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<p><img src="/./../images/45cddd93de2c0ed55b545584187d31c4.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<p><img src="/./../images/f35f0585e9eafe6c48050ff1feb2b556.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<h3><span id="修改视图">修改视图</span></h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">create</span> <span class="keyword">or</span> replace <span class="keyword">view</span> 视图名 <span class="keyword">as</span> 子查询;</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<p><img src="/./../images/5029e83e9639805f7466b7ccd0a348f4.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<h3><span id="删除视图">删除视图</span></h3><figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">drop</span> <span class="keyword">view</span> [if <span class="keyword">exists</span>] 视图名;</span><br></pre></td></tr></table></figure>

<p><img src="" alt="点击并拖拽以移动"></p>
<p><img src="/./../images/72a1904051fc3f1d9c2d60315ffc86aa.png" alt="img"><img src="" alt="点击并拖拽以移动"> </p>
<hr>
<p>子查询</p>
<hr>
<p> <strong>如有错误，欢迎指正！！！</strong></p>
</article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta"><i class="fas fa-circle-user fa-fw"></i>文章作者: </span><span class="post-copyright-info"><a href="http://xuanskeys.github.io">xuanskeys</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta"><i class="fas fa-square-arrow-up-right fa-fw"></i>文章链接: </span><span class="post-copyright-info"><a href="http://xuanskeys.github.io/2025/04/20/Oracle/">http://xuanskeys.github.io/2025/04/20/Oracle/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta"><i class="fas fa-circle-exclamation fa-fw"></i>版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来源 <a href="http://xuanskeys.github.io" target="_blank">XuanCode</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/1/">1</a></div><div class="post-share"><div class="social-share" data-image="/image/person.jpg" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><a class="pagination-related" href="/2025/04/20/%E6%95%B0%E6%8D%AE%E5%BA%93/" title="MySQL基础篇"><div class="cover" style="background: var(--default-bg-color)"></div><div class="info"><div class="info-1"><div class="info-item-1">上一篇</div><div class="info-item-2">MySQL基础篇</div></div><div class="info-2"><div class="info-item-1">数据库基本操作启动与停止1.第一种方式：1&gt;以管理员身份运行cmd   2&gt;在命令行窗口中输入: 123启动:net start mysql80停止:net stop mysql80   2.第二种方式:1&gt;Win+R快捷方式打开如下： ​    输入：services.msc   2&gt;找到MySQL80   3&gt;双击：   4&gt;这里我选择的是开机自启动 客户端连接1.第一种方式：通过MySQL提供的客户端命令行工具    2.第二种方式：通过命令行工具执行命令1mysql [-h 127.0.0.1] [-P 3306] -u 用户 -p   注意： 1.[]中可省略 2.使用这种方式时，需要配置PATH环境变量   SQL  1.DDL(数据定义语言)数据库操作查询所有数据库:1show databases;   查询当前数据库:1select database();   创建数据库:1create database [if not exists] 数据库名 [default charset 字符集] [collate...</div></div></div></a><a class="pagination-related" href="/2025/04/20/JUC1/" title="JUC并发编程1(初识进程和线程)"><div class="cover" style="background: var(--default-bg-color)"></div><div class="info text-right"><div class="info-1"><div class="info-item-1">下一篇</div><div class="info-item-2">JUC并发编程1(初识进程和线程)</div></div><div class="info-2"><div class="info-item-1"> 初识进程和线程初识进程：定义：  进程（Process）是计算机中的程序关于某数据集合上的一次运行活动，是系统进行资源分配的基本单位，是操作系统结构的基础。在早期面向进程设计的计算机结构中，进程是程序的基本执行实体；在当代面向线程设计的计算机结构中，进程是线程的容器。程序是指令、数据及其组织形式的描述，进程是程序的实体。（百度百科） 进程由程序、数据和进程控制块三部分组成。   什么是进程？ 狭义定义：进程是正在运行的程序的实例。 广义定义：进程是一个具有一定独立功能的程序关于某个数据集合的一次运行活动。它是操作系统动态执行的基本单元，在传统的操作系统中，进程既是基本的分配单元，也是基本的执行单元。   eg：进程可以看做是程序的实例，你可以打开多个程序，每一个程序就是一个进程（比如你重复打开QQ登录不同的用户，每一个用户登录的那个程序就是一个进程）。   如果你关闭一个窗口，那么这个进程也就结束了  概念：1.进程是一个实体。 ...</div></div></div></a></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span>相关推荐</span></div><div class="relatedPosts-list"><a class="pagination-related" href="/2025/04/20/JUC1/" title="JUC并发编程1(初识进程和线程)"><div class="cover" style="background: var(--default-bg-color)"></div><div class="info text-center"><div class="info-1"><div class="info-item-1"><i class="far fa-calendar-alt fa-fw"></i> 2025-04-20</div><div class="info-item-2">JUC并发编程1(初识进程和线程)</div></div><div class="info-2"><div class="info-item-1"> 初识进程和线程初识进程：定义：  进程（Process）是计算机中的程序关于某数据集合上的一次运行活动，是系统进行资源分配的基本单位，是操作系统结构的基础。在早期面向进程设计的计算机结构中，进程是程序的基本执行实体；在当代面向线程设计的计算机结构中，进程是线程的容器。程序是指令、数据及其组织形式的描述，进程是程序的实体。（百度百科） 进程由程序、数据和进程控制块三部分组成。   什么是进程？ 狭义定义：进程是正在运行的程序的实例。 广义定义：进程是一个具有一定独立功能的程序关于某个数据集合的一次运行活动。它是操作系统动态执行的基本单元，在传统的操作系统中，进程既是基本的分配单元，也是基本的执行单元。   eg：进程可以看做是程序的实例，你可以打开多个程序，每一个程序就是一个进程（比如你重复打开QQ登录不同的用户，每一个用户登录的那个程序就是一个进程）。   如果你关闭一个窗口，那么这个进程也就结束了  概念：1.进程是一个实体。 ...</div></div></div></a><a class="pagination-related" href="/2025/04/20/JUC2/" title="Java并发编程2(锁-Sychronized)"><div class="cover" style="background: var(--default-bg-color)"></div><div class="info text-center"><div class="info-1"><div class="info-item-1"><i class="far fa-calendar-alt fa-fw"></i> 2025-04-20</div><div class="info-item-2">Java并发编程2(锁-Sychronized)</div></div><div class="info-2"><div class="info-item-1">认识Java对象头  32位虚拟机对象头：   64位虚拟机对象头：     1.Mark Word（标记字）:  Mark Word是对象头的一部分，用于存储对象自身的哈希码、GC分代年龄、锁状态标志、线程持有的锁、偏向线程ID（或偏向时间戳）、偏向模式以及锁的状态等信息。 标记字的大小和具体内容可能因JVM实现的不同而有所变化。例如，在64位JVM上，默认情况下Mark Word占用64位（8字节），而在32位JVM上则是32位（4字节）。  2.Class Pointer（类指针）:  这是指向该对象对应类（Class）的指针，通过这个指针可以访问到对象所属类的元数据（如方法表、字段描述等）。类指针的大小依赖于JVM的具体实现及其是否开启了压缩指针（Compressed Oop）选项。 在某些情况下，比如当使用了-XX:+UseCompressedClassPointers选项时，类指针会被压缩以节省内存。  3.Array...</div></div></div></a><a class="pagination-related" href="/2025/04/20/JUC4/" title="Java并发编程4（JUC篇）"><div class="cover" style="background: var(--default-bg-color)"></div><div class="info text-center"><div class="info-1"><div class="info-item-1"><i class="far fa-calendar-alt fa-fw"></i> 2025-04-20</div><div class="info-item-2">Java并发编程4（JUC篇）</div></div><div class="info-2"><div class="info-item-1">本篇文章重点介绍JUC（java.util.concurrent）  JUC是”java.util.concurrent”包的简称，它是Java提供的一个并发工具包，旨在简化多线程编程，提供了丰富的类和接口来帮助开发者更高效、更安全地编写并发程序。JUC包增强了Java对并发的支持，解决了传统多线程编程中的一些难题，如死锁、竞争条件和资源管理等。    原子变量  基本类型原子变量 AtomicInteger  提供对整型值的原子操作，如加法、减法等。 方法示例：incrementAndGet(), decrementAndGet(), addAndGet(int delta), compareAndSet(int expect, int update)。  AtomicLong  类似于AtomicInteger，但是针对长整型（long）值。 方法与AtomicInteger相似，适用于需要处理较大数值的情况。  AtomicBoolean  支持布尔类型的原子操作。 方法示例：get(), set(boolean newValue),...</div></div></div></a><a class="pagination-related" href="/2025/04/20/JUC3/" title="Java并发编程3(CAS)"><div class="cover" style="background: var(--default-bg-color)"></div><div class="info text-center"><div class="info-1"><div class="info-item-1"><i class="far fa-calendar-alt fa-fw"></i> 2025-04-20</div><div class="info-item-2">Java并发编程3(CAS)</div></div><div class="info-2"><div class="info-item-1">Java内存模型(JMM)概念百度百科：java内存模型_百度百科  Java内存模型（Java Memory Model,...</div></div></div></a><a class="pagination-related" href="/2025/04/20/Java%E8%99%9A%E6%8B%9F%E6%9C%BA/" title="Java虚拟机"><div class="cover" style="background: var(--default-bg-color)"></div><div class="info text-center"><div class="info-1"><div class="info-item-1"><i class="far fa-calendar-alt fa-fw"></i> 2025-04-20</div><div class="info-item-2">Java虚拟机</div></div><div class="info-2"><div class="info-item-1">JVM的概念百度百科：java虚拟机 什么是虚拟机？虚拟机是一种抽象化的计算机，通过在实际的计算机上仿真模拟各种计算机功能来实现的。 为什么要有JVM？  Java设计的初衷是使要建的能在任何平台上运行的程序不需要再在每个单独的平台上由程序员进行重写或重编译。 Java虚拟机使这个愿望变为可能，因为它能知道每条指令的长度和平台的其他特性。 JVM的设计目标是提供一个基于抽象规格描述的计算机模型，为解释程序开发人员提供的任何系统上运行。   什么是java虚拟机?JVM全称Java Virtual...</div></div></div></a><a class="pagination-related" href="/2025/04/20/Java%E9%9D%A2%E5%90%91%E5%AF%B9%E8%B1%A1%E7%BC%96%E7%A8%8B/" title="Java面向对象编程"><div class="cover" style="background: var(--default-bg-color)"></div><div class="info text-center"><div class="info-1"><div class="info-item-1"><i class="far fa-calendar-alt fa-fw"></i> 2025-04-20</div><div class="info-item-2">Java面向对象编程</div></div><div class="info-2"><div class="info-item-1">什么是面向对象编程(OOP)? 它将数据和相关操作封装在对象中，通过对象之间的交互来解决问题。 简单来说，就是世界上所有的物品，都可以是一个对象，对象是一种特殊的数据结构，里面存储物品的相关属性信息，类似于一张表结构。 类就相当于对象的一个模版，结构相同的对象可以使用同一个类来构造   JVM虚拟机JVM是什么? JVM（Java虚拟机）并不是直接安装在操作系统上的一个单独的实体或文件夹，而是一种抽象的计算模型，它通常是由一个程序或者软件包的一部分来实现的。当你在计算机上安装Java运行环境（例如，Java Development Kit, JDK 或者 Java Runtime Environment, JRE）时，实际上就包含了JVM的实现 当你运行一个Java程序时，比如通过命令行输入java...</div></div></div></a></div></div><hr class="custom-hr"/><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i><span> 评论</span></div></div><div class="comment-wrap"><div><div id="gitalk-container"></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info text-center"><div class="avatar-img"><img src="/image/person.jpg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info-name">xuanskeys</div><div class="author-info-description"></div><div class="site-data"><a href="/archives/"><div class="headline">文章</div><div class="length-num">10</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">1</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">5</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/xuanskeys"><i class="fab fa-github"></i><span>Follow Me</span></a></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">欢迎来到XuanCode。更多详细信息请前往CSDN：https://blog.csdn.net/m0_73569492?type=blog</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link"><span class="toc-number">1.</span> <span class="toc-text">前言：</span></a></li><li class="toc-item toc-level-1"><a class="toc-link"><span class="toc-number">2.</span> <span class="toc-text">准备工作：</span></a></li><li class="toc-item toc-level-1"><a class="toc-link"><span class="toc-number">3.</span> <span class="toc-text">登录：</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link"><span class="toc-number">3.1.</span> <span class="toc-text">1.打开SQL Plus命令行工具</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link"><span class="toc-number">3.1.1.</span> <span class="toc-text">第一种方式：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link"><span class="toc-number">3.1.2.</span> <span class="toc-text">第二种方式：</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link"><span class="toc-number">3.2.</span> <span class="toc-text">2.以不同用户登录</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link"><span class="toc-number">3.2.0.1.</span> <span class="toc-text">SYSTEM（普通管理员）：</span></a></li><li class="toc-item toc-level-4"><a class="toc-link"><span class="toc-number">3.2.0.2.</span> <span class="toc-text">SYS(超级管理员)：</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link"><span class="toc-number">3.2.0.2.1.</span> <span class="toc-text">不显示密码方式：</span></a></li><li class="toc-item toc-level-5"><a class="toc-link"><span class="toc-number">3.2.0.2.2.</span> <span class="toc-text">显示密码方式：</span></a></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link"><span class="toc-number">3.2.0.3.</span> <span class="toc-text">SCOTT（普通用户）：</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link"><span class="toc-number">3.2.0.3.1.</span> <span class="toc-text">若是出现被锁住的情况：</span></a></li><li class="toc-item toc-level-5"><a class="toc-link"><span class="toc-number">3.2.0.3.2.</span> <span class="toc-text">解决方法：</span></a></li></ol></li></ol></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link"><span class="toc-number">4.</span> <span class="toc-text">SQL基本命令</span></a></li><li class="toc-item toc-level-1"><a class="toc-link"><span class="toc-number">5.</span> <span class="toc-text">1.数据定义语言（DDL）</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link"><span class="toc-number">5.1.</span> <span class="toc-text">数据库操作</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link"><span class="toc-number">5.1.1.</span> <span class="toc-text">查询所有用户：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link"><span class="toc-number">5.1.2.</span> <span class="toc-text">查看当前用户：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link"><span class="toc-number">5.1.3.</span> <span class="toc-text">创建表空间：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link"><span class="toc-number">5.1.4.</span> <span class="toc-text">创建用户并指定其表空间：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link"><span class="toc-number">5.1.5.</span> <span class="toc-text">给用户授予dba的权限（超级管理员）：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link"><span class="toc-number">5.1.6.</span> <span class="toc-text"></span></a></li><li class="toc-item toc-level-3"><a class="toc-link"><span class="toc-number">5.1.7.</span> <span class="toc-text">删除表空间：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link"><span class="toc-number">5.1.8.</span> <span class="toc-text">删除用户（超级管理员）：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link"><span class="toc-number">5.1.9.</span> <span class="toc-text">切换用户登录：</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link"><span class="toc-number">5.2.</span> <span class="toc-text">表操作</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link"><span class="toc-number">5.2.1.</span> <span class="toc-text">查询：</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link"><span class="toc-number">5.2.1.1.</span> <span class="toc-text">查询某个用户下所有表名：</span></a></li><li class="toc-item toc-level-4"><a class="toc-link"><span class="toc-number">5.2.1.2.</span> <span class="toc-text">查询某个用户下表个数：</span></a></li><li class="toc-item toc-level-4"><a class="toc-link"><span class="toc-number">5.2.1.3.</span> <span class="toc-text">查询某个用户的表结构：</span></a></li><li class="toc-item toc-level-4"><a class="toc-link"><span class="toc-number">5.2.1.4.</span> <span class="toc-text">查询指定表的建表语句：</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link"><span class="toc-number">5.2.2.</span> <span class="toc-text">创建：</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link"><span class="toc-number">5.2.2.1.</span> <span class="toc-text">数据类型：</span></a></li><li class="toc-item toc-level-4"><a class="toc-link"><span class="toc-number">5.2.2.2.</span> <span class="toc-text">创建表空间：</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link"><span class="toc-number">5.2.2.2.1.</span> <span class="toc-text"></span></a></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link"><span class="toc-number">5.2.2.3.</span> <span class="toc-text">创建表：</span></a></li><li class="toc-item toc-level-4"><a class="toc-link"><span class="toc-number">5.2.2.4.</span> <span class="toc-text">给表添加注释：</span></a></li><li class="toc-item toc-level-4"><a class="toc-link"><span class="toc-number">5.2.2.5.</span> <span class="toc-text">给字段添加注释：</span></a></li><li class="toc-item toc-level-4"><a class="toc-link"><span class="toc-number">5.2.2.6.</span> <span class="toc-text">表备份：</span></a></li><li class="toc-item toc-level-4"><a class="toc-link"><span class="toc-number">5.2.2.7.</span> <span class="toc-text">给表添加一列：</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link"><span class="toc-number">5.2.3.</span> <span class="toc-text">修改：</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link"><span class="toc-number">5.2.3.1.</span> <span class="toc-text">重命名表：</span></a></li><li class="toc-item toc-level-4"><a class="toc-link"><span class="toc-number">5.2.3.2.</span> <span class="toc-text">添加字段：</span></a></li><li class="toc-item toc-level-4"><a class="toc-link"><span class="toc-number">5.2.3.3.</span> <span class="toc-text">修改字段名：</span></a></li><li class="toc-item toc-level-4"><a class="toc-link"><span class="toc-number">5.2.3.4.</span> <span class="toc-text">修改数据类型：</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link"><span class="toc-number">5.2.4.</span> <span class="toc-text">删除：</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link"><span class="toc-number">5.2.4.1.</span> <span class="toc-text">删除表字段：</span></a></li><li class="toc-item toc-level-4"><a class="toc-link"><span class="toc-number">5.2.4.2.</span> <span class="toc-text">删除表：</span></a></li><li class="toc-item toc-level-4"><a class="toc-link"><span class="toc-number">5.2.4.3.</span> <span class="toc-text">删除表空间：</span></a></li><li class="toc-item toc-level-4"><a class="toc-link"><span class="toc-number">5.2.4.4.</span> <span class="toc-text">删除指定表并重新创建该表：</span></a></li></ol></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link"><span class="toc-number">6.</span> <span class="toc-text">2.数据操作语言（DML）</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link"><span class="toc-number">6.1.</span> <span class="toc-text">添加数据（insert）</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link"><span class="toc-number">6.1.1.</span> <span class="toc-text">给指定字段添加数据：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link"><span class="toc-number">6.1.2.</span> <span class="toc-text">给表中批量添加数据：</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link"><span class="toc-number">6.2.</span> <span class="toc-text">修改数据（update）</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link"><span class="toc-number">6.2.1.</span> <span class="toc-text">修改数据：</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link"><span class="toc-number">6.3.</span> <span class="toc-text">删除数据（delete）</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link"><span class="toc-number">6.3.1.</span> <span class="toc-text">删除数据：</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link"><span class="toc-number">6.4.</span> <span class="toc-text"></span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link"><span class="toc-number">7.</span> <span class="toc-text">3.数据查询语言（DQL）</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link"><span class="toc-number">7.1.</span> <span class="toc-text">编写顺序：</span></a></li><li class="toc-item toc-level-2"><a class="toc-link"><span class="toc-number">7.2.</span> <span class="toc-text">执行顺序：</span></a></li><li class="toc-item toc-level-2"><a class="toc-link"><span class="toc-number">7.3.</span> <span class="toc-text">基本查询</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link"><span class="toc-number">7.3.1.</span> <span class="toc-text">查询多个字段：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link"><span class="toc-number">7.3.2.</span> <span class="toc-text">设置别名：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link"><span class="toc-number">7.3.3.</span> <span class="toc-text">去除重复记录：</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link"><span class="toc-number">7.4.</span> <span class="toc-text">条件查询</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link"><span class="toc-number">7.4.1.</span> <span class="toc-text">语法：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link"><span class="toc-number">7.4.2.</span> <span class="toc-text"></span></a></li><li class="toc-item toc-level-3"><a class="toc-link"><span class="toc-number">7.4.3.</span> <span class="toc-text">条件：</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link"><span class="toc-number">7.5.</span> <span class="toc-text">聚合函数</span></a></li><li class="toc-item toc-level-2"><a class="toc-link"><span class="toc-number">7.6.</span> <span class="toc-text">分组查询</span></a></li><li class="toc-item toc-level-2"><a class="toc-link"><span class="toc-number">7.7.</span> <span class="toc-text">排序查询</span></a></li><li class="toc-item toc-level-2"><a class="toc-link"><span class="toc-number">7.8.</span> <span class="toc-text">分页查询</span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link"><span class="toc-number">8.</span> <span class="toc-text">4.数据控制语言（DCL）</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link"><span class="toc-number">8.1.</span> <span class="toc-text">管理用户</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link"><span class="toc-number">8.1.1.</span> <span class="toc-text">查看当前用户：</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link"><span class="toc-number">8.2.</span> <span class="toc-text">权限控制</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link"><span class="toc-number">8.2.1.</span> <span class="toc-text">查询用户权限：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link"><span class="toc-number">8.2.2.</span> <span class="toc-text">授予权限：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link"><span class="toc-number">8.2.3.</span> <span class="toc-text">回收权限：</span></a></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link"><span class="toc-number">9.</span> <span class="toc-text">函数</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link"><span class="toc-number">9.1.</span> <span class="toc-text">使用</span></a></li><li class="toc-item toc-level-2"><a class="toc-link"><span class="toc-number">9.2.</span> <span class="toc-text">sys.dual</span></a></li><li class="toc-item toc-level-2"><a class="toc-link"><span class="toc-number">9.3.</span> <span class="toc-text">字符串函数</span></a></li><li class="toc-item toc-level-2"><a class="toc-link"><span class="toc-number">9.4.</span> <span class="toc-text">数值函数</span></a></li><li class="toc-item toc-level-2"><a class="toc-link"><span class="toc-number">9.5.</span> <span class="toc-text">日期函数</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link"><span class="toc-number">9.5.1.</span> <span class="toc-text">日期表示:</span></a></li><li class="toc-item toc-level-3"><a class="toc-link"><span class="toc-number">9.5.2.</span> <span class="toc-text">函数概述：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link"><span class="toc-number">9.5.3.</span> <span class="toc-text">eg:</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link"><span class="toc-number">9.5.3.1.</span> <span class="toc-text">sysdate：</span></a></li><li class="toc-item toc-level-4"><a class="toc-link"><span class="toc-number">9.5.3.2.</span> <span class="toc-text">next_day():</span></a></li><li class="toc-item toc-level-4"><a class="toc-link"><span class="toc-number">9.5.3.3.</span> <span class="toc-text">  last_day():</span></a></li><li class="toc-item toc-level-4"><a class="toc-link"><span class="toc-number">9.5.3.4.</span> <span class="toc-text">round() :</span></a></li><li class="toc-item toc-level-4"><a class="toc-link"><span class="toc-number">9.5.3.5.</span> <span class="toc-text">  add_months():</span></a></li><li class="toc-item toc-level-4"><a class="toc-link"><span class="toc-number">9.5.3.6.</span> <span class="toc-text">months_between():</span></a></li><li class="toc-item toc-level-4"><a class="toc-link"><span class="toc-number">9.5.3.7.</span> <span class="toc-text">extract():</span></a></li></ol></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link"><span class="toc-number">10.</span> <span class="toc-text">约束</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link"><span class="toc-number">10.1.</span> <span class="toc-text">概念</span></a></li><li class="toc-item toc-level-2"><a class="toc-link"><span class="toc-number">10.2.</span> <span class="toc-text">分类</span></a></li><li class="toc-item toc-level-2"><a class="toc-link"><span class="toc-number">10.3.</span> <span class="toc-text">外键约束</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link"><span class="toc-number">10.3.1.</span> <span class="toc-text">添加外键：</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link"><span class="toc-number">10.3.1.1.</span> <span class="toc-text">在创建表的时候添加：</span></a></li><li class="toc-item toc-level-4"><a class="toc-link"><span class="toc-number">10.3.1.2.</span> <span class="toc-text">sql语句添加（alter）：</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link"><span class="toc-number">10.3.2.</span> <span class="toc-text">查询外键</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link"><span class="toc-number">10.3.2.1.</span> <span class="toc-text">根据外键名称查看外键所在位置：</span></a></li><li class="toc-item toc-level-4"><a class="toc-link"><span class="toc-number">10.3.2.2.</span> <span class="toc-text">查找表的外键：</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link"><span class="toc-number">10.3.3.</span> <span class="toc-text">删除外键</span></a></li></ol></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link"><span class="toc-number">11.</span> <span class="toc-text">多表查询</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link"><span class="toc-number">11.1.</span> <span class="toc-text">基本概念</span></a></li><li class="toc-item toc-level-2"><a class="toc-link"><span class="toc-number">11.2.</span> <span class="toc-text">基本结构</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link"><span class="toc-number">11.2.1.</span> <span class="toc-text">内连接+外连接：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link"><span class="toc-number">11.2.2.</span> <span class="toc-text">自连接：</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link"><span class="toc-number">11.3.</span> <span class="toc-text">关系运算</span></a></li><li class="toc-item toc-level-2"><a class="toc-link"><span class="toc-number">11.4.</span> <span class="toc-text">大学模式：</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link"><span class="toc-number">11.4.1.</span> <span class="toc-text">创建基本表结构：</span></a></li><li class="toc-item toc-level-3"><a class="toc-link"><span class="toc-number">11.4.2.</span> <span class="toc-text">插入数据：</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link"><span class="toc-number">11.5.</span> <span class="toc-text">内连接 （自然连接）</span></a></li><li class="toc-item toc-level-2"><a class="toc-link"><span class="toc-number">11.6.</span> <span class="toc-text">外连接</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link"><span class="toc-number">11.6.1.</span> <span class="toc-text">左外连接</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link"><span class="toc-number">11.7.</span> <span class="toc-text"></span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link"><span class="toc-number">11.7.1.</span> <span class="toc-text">右外连接</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link"><span class="toc-number">11.8.</span> <span class="toc-text"></span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link"><span class="toc-number">11.8.1.</span> <span class="toc-text">全连接</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link"><span class="toc-number">11.9.</span> <span class="toc-text">自连接</span></a></li><li class="toc-item toc-level-2"><a class="toc-link"><span class="toc-number">11.10.</span> <span class="toc-text"></span></a></li></ol></li><li class="toc-item toc-level-1"><a class="toc-link"><span class="toc-number">12.</span> <span class="toc-text">视图</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link"><span class="toc-number">12.1.</span> <span class="toc-text">基本概念</span></a></li><li class="toc-item toc-level-2"><a class="toc-link"><span class="toc-number">12.2.</span> <span class="toc-text">基本操作</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link"><span class="toc-number">12.2.1.</span> <span class="toc-text">查看视图</span></a></li><li class="toc-item toc-level-3"><a class="toc-link"><span class="toc-number">12.2.2.</span> <span class="toc-text">创建视图</span></a></li><li class="toc-item toc-level-3"><a class="toc-link"><span class="toc-number">12.2.3.</span> <span class="toc-text">修改视图</span></a></li><li class="toc-item toc-level-3"><a class="toc-link"><span class="toc-number">12.2.4.</span> <span class="toc-text">删除视图</span></a></li></ol></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2025/04/20/%E6%9C%80%E7%9F%AD%E8%B7%AF%E9%97%AE%E9%A2%98/" title="最短路问题">最短路问题</a><time datetime="2025-04-20T02:09:44.000Z" title="发表于 2025-04-20 10:09:44">2025-04-20</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2025/04/20/Java%E8%99%9A%E6%8B%9F%E6%9C%BA/" title="Java虚拟机">Java虚拟机</a><time datetime="2025-04-20T02:07:29.000Z" title="发表于 2025-04-20 10:07:29">2025-04-20</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2025/04/20/%E5%9F%BA%E7%A1%80%E7%AE%97%E6%B3%95/" title="基础算法">基础算法</a><time datetime="2025-04-20T02:03:22.000Z" title="发表于 2025-04-20 10:03:22">2025-04-20</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2025/04/20/JUC4/" title="Java并发编程4（JUC篇）">Java并发编程4（JUC篇）</a><time datetime="2025-04-20T02:01:01.000Z" title="发表于 2025-04-20 10:01:01">2025-04-20</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2025/04/20/JUC3/" title="Java并发编程3(CAS)">Java并发编程3(CAS)</a><time datetime="2025-04-20T01:59:28.000Z" title="发表于 2025-04-20 09:59:28">2025-04-20</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2025 By xuanskeys</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo 7.3.0</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly 5.3.5</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="日间和夜间模式切换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside-config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><a id="to_comment" href="#post-comment" title="前往评论"><i class="fas fa-comments"></i></a><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><div class="js-pjax"><script>(() => {
  const isShuoshuo = GLOBAL_CONFIG_SITE.pageType === 'shuoshuo'
  const option = null

  const commentCount = n => {
    const isCommentCount = document.querySelector('#post-meta .gitalk-comment-count')
    if (isCommentCount) {
      isCommentCount.textContent= n
    }
  }

  const initGitalk = (el, path) => {
    if (isShuoshuo) {
      window.shuoshuoComment.destroyGitalk = () => {
        if (el.children.length) {
          el.innerHTML = ''
          el.classList.add('no-comment')
        }
      }
    }

    const gitalk = new Gitalk({
      clientID: '',
      clientSecret: '',
      repo: 'xuanskeys.github.io',
      owner: 'xuanskeys',
      admin: ['xuanskeys'],
      updateCountCallback: commentCount,
      ...option,
      id: isShuoshuo ? path : (option && option.id) || 'd3f78be1ba12ceeb762c938426de4152'
    })

    gitalk.render('gitalk-container')
  }

  const loadGitalk = async(el, path) => {
    if (typeof Gitalk === 'function') initGitalk(el, path)
    else {
      await btf.getCSS('https://cdn.jsdelivr.net/npm/gitalk/dist/gitalk.min.css')
      await btf.getScript('https://cdn.jsdelivr.net/npm/gitalk/dist/gitalk.min.js')
      initGitalk(el, path)
    }
  }

  if (isShuoshuo) {
    'Gitalk' === 'Gitalk'
      ? window.shuoshuoComment = { loadComment: loadGitalk }
      : window.loadOtherComment = loadGitalk
    return
  }

  if ('Gitalk' === 'Gitalk' || !false) {
    if (false) btf.loadComment(document.getElementById('gitalk-container'), loadGitalk)
    else loadGitalk()
  } else {
    window.loadOtherComment = loadGitalk
  }
})()</script></div><script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script><script src="https://cdn.jsdelivr.net/gh/xiabo2/CDN@latest/fishes.js"></script><script id="canvas_nest" defer="defer" color="0,0,255" opacity="0.7" zIndex="-1" count="99" mobile="false" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/canvas-nest.min.js"></script><script id="click-heart" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/click-heart.min.js" async="async" mobile="false"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="text-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div><div id="local-search-stats-wrap"></div></div></div><div id="search-mask"></div><script src="/js/search/local-search.js"></script></div></div></body></html>